Part Number Hot Search : 
216125 216125 B66414 1460E 09105 NC7SV32 UPC7900 APTGF
Product Description
Full Text Search
 

To Download SAM4CM-14 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 description the atmel ? | smart sam4cm series represents a family of system-on-chip solutions for residential and polyphase metering applications. the devices offer up to class 0.2 metrology accuracy over a dynamic range of 3000:1 within the industrial temperature range and are compliant with ansi c12.20-2002 and iec 62053-22 standards. a seamless extension of atmel's sam4, sam4cp and sam4c family of microcontrollers and solutions for smart grid security and communications applications, these metrology-enabled devices offer an unprecedented level of integration and flexibility with dual 32-bit arm ? cortex ? -m4 risc processors running at a maximum speed of 120 mhz each (1) , up to 2 mbytes of embedded flash, 304 kbytes of sram and on-chip cache. the unique dual arm cortex -m4 architecture supports implementation of signal processing, application and communicati ons firmware in independent partitions, and offers the ab ility to extend program and data memory via parallel external bus interface (ebi) to ensure scalability of th e design to meet fu ture requirements. the peripheral set includes metrology-specific precision voltage reference, up to seven (7) simultaneously sampled sigma-delta adc subsystems supporting three (3) voltage and four (4) current measurement channels (polyphase versions only), an extensive set of embedded cryp tographic features, anti-tamper, floating point unit (fpu), four usarts, two ua rts, two twis, four spis, three 16-bit pwms, two 3-channel general-purpose 16-bit timers, 6-channel 10-bit adc, battery-backed rtc with <1 a consumption and a 38 x 6 segmented lcd controller. to ensure the distinct separation of metrology and application or communication functions, the sam4cm integrates a dedicat ed cortex-m4f core that manages all necessary metrology resources and memory. sam4cm series atmel | smart arm-based flash mcu datasheet
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 2 features ? application/master core ? arm cortex-m4 running at up to 120 mhz (1) ? memory protection unit (mpu) ? dsp instruction ? thumb ? -2 instruction set ? instruction and data cache cont roller with 2 kbytes cache memory ? memories ? up to 2 mbytes of embedded flash for program code (i-code bus) and program data (d-code bus) with built-in ecc (2-bit error detection and 1-bit correction per 128 bits) ? up to 256 kbytes of embedded sram (sram0) for program data (system bus) ? 8 kbytes of rom with embedded bootloader routines (uart) and in-application programming (iap) routines ? coprocessor (provides ability to separate application, communi cation or metrology functions) ? arm cortex-m4f running at up to 120 mhz (1) ? ieee ? 754 compliant, single-precision floating-point unit (fpu) ? dsp instruction ? thumb-2 instruction set ? instruction and data cache contro ller with 2 kbytes of cache memory ? memories ? up to 32 kbytes of embedded sram (sram1) for pr ogram code (i-code bus) and program data (d-code bus and system bus) ? up to 16 kbytes of embedded sram (sram2) for program data (system bus) ? symmetrical/asynchronous dual core architecture ? interrupt-based interprocessor communication ? asynchronous clocking ? one interrupt controller (nvic) for each core ? each peripheral irq routed to each nvic input ? cryptography ? high-performance aes 128 to 25 6 with various modes (gcm, cbc, ecb, cfb, cbc-mac, ctr) ? trng (up to 38 mbit/s stream, with tested diehard and fips) ? public key crypto accelerato r and associated rom library for rsa, ecc, dsa, ecdsa ? integrity check module (icm) based on secure hash algorithm (sha1, sha224, sha256), dma-assisted ? safety ? up to two physical anti-tamper detection i/os wit h time stamping and immediate clear of general backup registers ? security bit for device prot ection from jtag accesses ? shared system controller ? power supply ? embedded core and lcd voltage regulator for single-supply operation ? power-on-reset (por), brownout detector (bod) and dual watchdog for safe operation ? ultra-low-power backup mode (< 0.5 a typical @ 25c)
3 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? clock ? optional 3 to 20 mhz quartz or ceramic resonator oscillators with clock failure detection ? ultra-low-power 32.768 khz crystal oscillator for rtc with frequency monitoring ? high-precision 4/8/12 mhz factory-trimmed internal rc oscillator with on-the-fly trimming capability ? one high-frequency pll up to 240 mhz, one 8 mhz pll with internal 32 khz input, as source for high-frequency pll ? low-power slow clock internal rc oscillator as permanent clock ? ultra-low-power rtc with gregor ian and persian calendar, wavefo rm generation in low-power modes and clock calibration circuit ry for 32.768 khz crystal fr equency compensation circuitry ? up to 23 peripheral dma (pdc) channels ? shared peripherals ? one segmented lcd controller ? display capacity of 38 segments and 6 common terminals ? software-selectable lcd output voltage (contrast) ? low current consumption in low-power mode ? can be used in backup mode ? up to four usarts with iso7816, irda ? , rs-485, spi and manchester mode ? two 2-wire uarts with one uart (uart1) supporting optical transceiver providing an electrically isolated serial communication with hand-held equi pment, such as calibrato rs, compliant with ansi- c12.18 or iec62056-21 norms ? up to two 400 khz master/slave and multi-master two-wire interfaces (i 2 c compatible) ? up to four serial peripheral interfaces (spi) ? two 3-channel 16-bit timer/counters with capture, waveform, compare and pwm modes ? quadrature decoder logic and 2-bit gray up/down counter for stepper motor ? 3-channel 16-bit pulse width modulator ? 32-bit real-time timer ? energy metering analog front-end ? two-phase (sam4cms) or three-phase (sam4cmp) energy metering analog front-end ? works with the atmel mcu metrology library ? compliant with class 0.2 standards (ansi c12.20-2002 and iec 62053-22) ? four or seven sigma-delta adc measurement channels, 20-bit resolution, 102 db dynamic range ? current channels with pre-gain (x1, x2, x4, x8) supp ort directly connected shunt, current transformer and rogowsky coils sensors without any active components ? dedicated current channel for neutral current measurement (anti-tamper) ? 1.2v precision voltage reference. temperature dr ift: 10 ppm/c typ. with software correction using factory programmed calibration registers ? dedicated 2.8v ldo regulator to supply the analog front-end ? 3.0v to 3.6v operation, ultra-low-power: < 2.5 mw / channel @ 3.3v ? analog conversion block ? 8-channel, 500 ks/s, low-power 10-bit sar adc wit h digital averager providing 12-bit resolution at 30 ks/s ? software-controlled on-chip reference ranging from 1.6v to 3.4v ? temperature sensor and backup battery voltage measurement channel
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 4 ? debug ? star topology ahb-ap debug access port impl ementation with common sw-dp / swj-dp providing higher performance than daisy-chain topology ? debug synchronization between both cores (cross triggering to/from each core for halt and run mode) ? i/o ? up to 57 i/o lines with external in terrupt capability (e dge or level sensitivity), schmitt trigger, internal pull-up/pull-down, debouncing, gl itch filtering and on-die se ries resistor termination ? package ? 100-lead lqfp, 14 x 14 mm, pitch 0.5 mm note: 1. 120 mhz: -40c/+85c, vddcore = 1.2v
5 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1. configuration summary the sam4cm devices differ in memory size, package and features. table 1-1 summarizes the sam4cm device configurations.. notes: 1. 1/4 + 3 = number of spi cont rollers / number of chip selects + number of usarts with spi mode. 2. one channel is reserved for internal temperatur e sensor and one channel for vddbu measurement. table 1-1. configuration summary feature sam4cmp32c sam4cmp16c sam4cmp8c sam4cms32c sam4cms16c sam4cms8c flash 2048 kbytes 1024 kbytes 512 kbytes 2048 kbytes 1024 kbytes 512 kbytes sram 256 + 32 +16 kbytes 128 + 16 +8 kbytes 256 + 32 +16 kbytes 128 + 16 +8 kbytes package lqfp 100 number of pios 52 57 external bus interface 8-bit data 8-bit data 16-bit timer 6 channels 6 channels 16-bit pwm 3 channels 3 channels uart / usart 2/3 2/4 spi (1) 1/4 + 3 1/4 + 4 twi 22 10-bit adc channels (2) 66 energy metering analog front -end 7 channels (3 voltages, 4 currents) 4 channels (2 voltages, 2 currents) cryptography aes, cpkcc, icm (sha), trng ae s, cpkcc, icm (sha), trng segmented lcd 33 segments 6 commons 38 segments 6 commons anti-tampering inputs 12 flash page size 512 bytes 512 bytes flash pages 2 2048 2048 1024 2 2048 2048 1024 flash lock region size 8 kbytes 8 kbytes flash lock bits 2 128 128 64 2 128 128 64
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 6 2. block diagram figure 2-1. sam4cm series 100-pin block diagram external bus interface d[7:0] a[23:0] nandale nandcle ncs0 ncs1 ncs2 ncs3 nrd nwe static memory controller 0 static memory controller 1 high speed ahb multilayer bus matrix 0 sam4cm pdc0 uart0 twck0 twd0 twd1 urxd0 utxd0 twck1 twi0 twi1 rom (sam-ba pkcl) flash 2x1024 kb or 1024 kb or 512 kb sram 0 256 kb or 128 kb advref trng aes icm (sha) (integrity check module) dma cpkcc (classical public key cryptography controller - rsa) ad[0..3] temperature sensor 10-bit adc ahb to apb bridge 0 sram 2 8 or 16 kb tdi tdo/traceswo tms/swdio tck/swclk jtagsel sram 1 16 or 32 kb pio com[0..5] segment lcd controller seg[0..39] asynchronous ahb to ahb bridge uart1 urxd1 utxd1 pwm0, pwm1, pwm3 pwm ipc1 ipc0 high speed ahb multilayer bus matrix 1 n v i c cortex-m4f cm4p1 dsp fpu ahb-ap system bus n v i c dsp ahb-ap mpu icode / dcode bus icode / dcode bus system bus cortex-m4 cm4p0 ahb to apb bridge 1 instr./data cache controller 2 kb cache memory i/d bus s bus s bus master master master master master/slave master/slave master master slave/master slave/master slave slave slave slave slave slave slave slave slave slave instr./data cache controller 2 kb cache memory peripheral dma 1 peripheral dma 0 master ip0 ip1 ip2 ip3 in0 in1 in2 in3 x2 or x4 vp1 vp2 vp3 vn energy metering analog front-end vddin_afe vdda vref_afe emafe i/f voltage reference + temp. sensor ldo 2.8v tc[3..5] timer counter b tiob[4:5] tclk[4:5] tioa[4:5] voltage reference sub-system 0 sub-system 1 pmc pio controller plla 8 mhz pllb 80 - 240 mhz rc osc 4/8/12 mhz xtal osc 3 - 20 mhz system controller tst pck0-pck2 xin xout automatic power switch core voltage regulator lcd voltage regulator vddbu vddio vddpll vddin vddout vddlcd real-time timer 32 khz xtal osc supply controller backup zone reset controller anti-tampering backup reg (16) por real-time clock time stamping rc 32 khz supp.mon nrst fwup xin32 xout32 vddcore erase tmp1 tmp0 rtcout0 shdn pdc0 spi0 spi0_npcs0 spi0_npcs1 spi0_npcs2 spi0_npcs3 spi0_miso spi0_mosi spck0 usart2 rxd2 txd2 sck2 rts2 cts2 usart3 rxd3 txd3 sck3 rts3 cts3 timer counter a tc[0..2] tiob[0:2] tclk[0:2] tioa[0:2] pdc0 pdc0 pdc0 usart1 rxd1 txd1 sck1 rts1 cts1 pdc0 usart0 rxd0 txd0 sck0 rts0 cts0 pdc0 pdc0 pdc0 digital averager pdc1 x2 or x3 optical port serial wire and jtag debug port (sw-dp/swj-dp) dual watchdog wkup[0:13] vddlcd wkup[0:13]
7 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 3. signal description table 3-1 provides details on signal names classified by peripheral. table 3-1. signal description list signal name function type active level voltage reference comments power supplies vddio see table 5-1 on page 14 power ?? ? vddbu ?? ? vddin ?? ? vddlcd ?? ? vddout ?? ? vddpll ?? ? vddcore ? ? ? vddin_afe ? ? ? vdda ?? ? gnd ground ?? ? gnda ?? ? gndref ?? ? clocks, oscillators and plls xin main crystal oscillator input analog digital ? vddio ? xout main crystal oscillator output ? xin32 slow clock crystal oscillator input analog digital ? vddbu xout32 slow clock crystal oscillator output ? pck0?pck2 programmable clock output output ? vddio ? real-time clock rtcout0 programmable rtc waveform output digital output ?vddio ? supply controller fwup force wake-up input digital input low vddbu external pull-up needed tmp0 anti-tampering input 0 digital input ?vddbu ? tmp1 anti-tampering input 1 digital input ?vddio ? shdn active low shutdown control digital output ?vddbu 0: the device is in backup mode. 1: the device is running (not in ba ckup mode). wkup0 wake-up input 0 digital input ?vddbu ? wkup1?13 wake-up input 1 to 13 digital input ?vddio ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 8 serial wire/jtag debug port - swj-dp tck/swclk test clock/serial wire clock digital input ? vddio ? tdi test data in ? tdo/traceswo test data out / trace asynchronous data out digital output ? vddio ? tms/swdio test mode select input / serial wire input/output digital i/o ? jtagsel jtag selection digital input high vddbu permanent internal pull-down flash memory erase flash and nvm configuration bits erase command digital input high vddio permanent internal pull-down reset/test nrst synchronous microcontroller reset digital i/o low vddio permanent internal pull-up tst test select digital input ?vddbu permanent internal pull-down universal asynchronous receiver transceiver - uartx urxdx uart receive data digital/ analog input ? vddio analog mode for optical receiver utxdx uart transmit data digital output ?? pio controller - pioa - piob - pioc pa0?pa31 parallel io controller a digital i/o ? vddio ? pb0?pb21 parallel io controller b ? ? pc0?pc9 parallel io controller c digital i/o ?vddio ? external bus interface d[7:0] data bus digital i/o ? vddio ? a[23:0] address bus digital output ?? static memory controller - smc ncs0?ncs3 chip select lines digital output low vddio ? nrd read signal ? nwe write enable ? nbs0?nbs1 byte mask signal ? nwr0?nwr1 write signal ? table 3-1. signal descrip tion list (continued) signal name function type active lev e l voltage reference comments
9 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 universal synchronous asynchronous receiver transmitter - usartx sckx usartx serial clock digital i/o ? vddio ? txdx usartx transmit data digital output ?? rxdx usartx receive data digital input ? vddio ? rtsx usartx request to send digital output ?? ctsx usartx clear to send digital input ?? timer/counter - tc tclkx tc channel x external clock input digital input ? vddio ? tioax tc channel x i/o line a digital i/o ?? tiobx tc channel x i/o line b ? ? pulse width modulation controller - pwmc pwmx pwm waveform output for channel x digital output ?vddio ? serial peripheral interface - spi spi0_miso master in slave out digital input ? vddio ? spi0_mosi master out slave in digital output ?? spck0 spi serial clock ? ? spi0_npcs0 spi peripheral chip select 0 low npcs0 is also nss for slave mode spi0_npcs1? spi0_npcs3 spi peripheral chip select output low ? segmented lcd controller - slcdc com0?com5 common terminals output ? vddio ? seg0?seg39 segment terminals output ? ? two-wire interface - twi twdx twix two-wire serial data digital i/o ? vddio ? twckx twix two-wire serial clock digital output ?? table 3-1. signal descrip tion list (continued) signal name function type active level voltage reference comments
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 10 analog advref external voltage reference for adc analog input ?vddin ? 10-bit analog-to-digit al converter - adc ad0?ad3 analog inputs analog, digital ?vddio adc input range limited to [0..advref] fast flash programming interface - ffpi pgmen0?pgmen1 programming enabling digital input ? vddio ? pgmm0?pgmm3 programming mode ? ? pgmd0?pgmd15 programming data digital i/o ?? pgmrdy programming ready digital output high ? pgmnvalid data direction low ? pgmnoe programming read digital input low ? pgmncmd programming command low ? energy metering analog front end - emafe vref_afe precision 1.2v volt age reference input and output for emafe analog input / output ? vdda ? vpx voltage channel x, positive input analog input ?? vn voltage channels, common negative input ?? ipx current channel x, positive input ? ? inx current channel x, negative input ? ? table 3-1. signal descrip tion list (continued) signal name function type active level voltage reference comments
11 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 4. package and pinout 4.1 sam4cm series 100-lead lqfp package outline the sam4cm series 100-lead lqfp package has a 0.5 mm ball pitch and respects green standards. figure 4-1 shows the orientation of the 100-lead lqfp package . refer to the section ?mechanical characteristics? for the sam4cm series 100-lead lqfp package mechanical drawing. figure 4-1. orientation of the 100-lead lqfp package 12 5 26 50 51 75 76 100
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12 4.2 100-lead lqfp pinout table 4-1. sam4cmp32/sam4cmp16/ sam4cmp8 100-lead lqfp pinout 1 pb6 26 tdi/pb0 51 vddio 76 advref 2 pb7 27 tck/swclk/pb3 52 gnd 77 gnd 3 in2 28 tms/swdio/pb2 53 pa31 78 pb13/ad3 4 gnd 29 erase/pc9 54 gnd 79 pa5/ad2/pgmrdy 5ip2 30 tdo/traceswo /pb1 55 vddpll 80 pa4/ad1/pgmncmd 6 pb8 31 pc1 56 pa28 81 pa12/ad0/pgmd0 7 in1 32 pc6 57 pa27/pgmd15 82 vddin 8 ip1 33 vddio 58 pa6/pgmnoe 83 vddout 9 in0 34 vddbu 59 vddcore 84 vp3 10 ip0 35 fwup 60 pa3 85 vp2 11 gnd 36 jtagsel 61 pa21/pgmd9 86 vddcore 12 vddcore 37 shdn 62 pa22/pgmd10 87 vp1 13 pb9 38 tst 63 vddio 88 pa0/pgmen0 14 pb10 39 tmp0 64 vddin_afe 89 vn 15 pb11 40 xin32 65 ? 90 vref_afe 16 pb12 41 xout32 66 pa23/pgmd11 91 gndref 17 pb14 42 gnd 67 pa9/pgmm1 92 vddlcd 18 pb15 43 pb4 68 pa10/pgmm2 93 gnda 19 pa26/pgmd14 44 vddcore 69 pa11/pgmm3 94 vdda 20 pa25/pgmd13 45 pb5 70 pa13/pgmd1 95 in3 21 pa24/pgmd12 46 pc7 71 pa14/pgmd2 96 pa1/pgmen1 22 pa20/pgmd8 47 pc0 72 pa15/pgmd3 97 ip3 23 pa19/pgmd7 48 nrst 73 pa16/pgmd4 98 pa7/pgmnvalid 24 pa18/pgmd6 49 vddio 74 pa17/pgmd5 99 vddio 25 pa8/pgmm0 50 pa30 75 vddio 100 pa2
13 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 table 4-2. sam4cms32/sam4cms16/ sam4cms8 100-lead lqfp pinout 1 pb6 26 tdi/pb0 51 vddio 76 advref 2 pb7 27 tck/swclk/pb3 52 gnd 77 gnd 3 pb18 28 tms/swdio/pb2 53 pa31 78 pb13/ad3 4 gnd 29 erase/pc9 54 gnd 79 pa5/ad2/pgmrdy 5 pb19 30 tdo/traceswo /pb1 55 vddpll 80 pa4/ad1/pgmncm d 6 pb8 31 pc1 56 pa28 81 pa12/ad0/pgmd0 7 in1 32 pc6 57 pa27/pgmd15 82 vddin 8 ip1 33 vddio 58 pa6/pgmnoe 83 vddout 9 in0 34 vddbu 59 vddcore 84 pb21 10 ip0 35 fwup 60 pa3 85 vp2 11 gnd 36 jtagsel 61 pa21/pgmd9 86 vddcore 12 vddcore 37 sdhn 62 pa22/pgmd10 87 vp1 13 pb9 38 tst 63 vddio 88 pa0/pgmen0 14 pb10 39 tmp0 64 vddin_afe 89 vn 15 pb11 40 xin32 65 ? 90 vref_afe 16 pb12 41 xout32 66 pa23/pgmd11 91 gndref 17 pb14 42 gnd 67 pa9/pgmm1 92 vddlcd 18 pb15 43 pb4 68 pa10/pgmm2 93 gnda 19 pa26/pgmd14 44 vddcore 69 pa11/pgmm3 94 vdda 20 pa25/pgmd13 45 pb5 70 pa13/pgmd1 95 pb16/tmp1 21 pa24/pgmd12 46 pc7 71 pa14/pgmd2 96 pa1/pgmen1 22 pa20/pgmd8 47 pc0 72 pa15/pgmd3 97 pb17 23 pa19/pgmd7 48 nrst 73 pa16/pgmd4 98 pa7/pgmnvalid 24 pa18/pgmd6 49 vddio 74 pa17/pgmd5 99 vddio 25 pa8/pgmm0 50 pa30 75 vddio 100 pa2
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 14 5. power supply and power control 5.1 power supplies the sam4cm series has several types of power supply pins . in most cases, a single supply scheme for all power supplies (except vddbu) is possible. figure 5-1 below shows power domains according to the different power supply pins. figure 5-1. power domains table 5-1. power supply voltage ranges power supply range comments vddio 1.6v to 3.6v flash memory charge pumps supply for erase and program operations, and read operation. input/output buffers supply. emafe digital functions supply. restrictions on range may apply. refer to the section electrical characteristics. vddbu 1.6v to 3.6v backup area power supply. vddbu is automatically disconnected when vddio is present (> 1.9v). vddin 1.6v to 3.6v core voltage regulator supply, lcd voltage regulator supply, adc and programmable voltage reference supply. restrictions on range may apply. refer to the section electrical characteristics. vddlcd 2.5v to 3.6v lcd voltage regulator output. external lcd power supply input (lcd regulator not used). vddio/vddin must be supplied when the lcd controller is used. vddpll 1.08v to 1.32v plla and pllb supply. lcd analog buffers + switch array vddcore cortex-m4 (cm4p0) cortex-m4 (cm4p1) sram, rom flash logic peripherals (spi, usart,...) pio controller 10-bit adc, temp. sensor, voltage reference vddbu vddpll input / output buffers automatic power switch charge pumps vddin lcd voltage regulator core voltage regulator vddout rc osc 32 khz rtc, rtt, rstc, backup, reg, ... xtal osc 32 khz xtal osc 3 - 20 mhz rc osc 4 - 12 mhz plla, pllb vddlcd vddin_afe vdda vdda voltage regulator energy metering analog-front-end vddio or vddbu vddio
15 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 5.1.1 core voltage regulator the sam4cm series embeds a core voltage regulator that is managed by the supply controller. it features two operating modes: ? in normal mode, the quiescent current of the voltage regulator is less than 500 a when sourcing maximum load current, i.e. 120 ma. internal adaptive biasing ad justs the regulator quiescent current depending on the required load current. in wait mode , quiescent current is only 5 a. ? in backup mode, the voltage regulator consumes less than 100 na while its outp ut (vddout) is driven internally to gnd. the default output voltage is 1.20v and the start-up time to reach normal mode is less than 500 s. for further information, refer to core voltage regulator ch aracteristics in the section ?electrical characteristics?. 5.1.2 lcd voltage regulator the sam4cm embeds an adjustable lcd voltage regulat or that is managed by the supply controller. this internal regulator is designed to supply the segment lcd outputs. the lcd regulator output voltage is software selectable with 16 levels to adjust the display contrast. if not used, its output (vddlcd) can be bypassed (hi-z mode) and an external power supply can be provided onto the vddlcd pin. in this case , vddio still needs to be supplied. the lcd voltage regulator can be used in all power modes (backup, wait, sleep and active). for further information, refer to lcd voltage regulator ch aracteristics in the section ?electrical characteristics?. 5.1.3 automatic power switch the sam4cm features an automatic power switch bet ween vddbu and vddio. when vddio is present, the backup zone power supply is powered by vddio and current consumption on vddbu is about zero (around 100 na, typ.). when vddio is removed, the backup area of the device is supp lied from vddbu. switching between vddio and vddbu is transparent to the user. 5.1.4 emafe voltage regulator the sam4cm series embeds a 2.8v voltage regulator to supply its energy metering analog front-end (the vdda pin). this regulator is under software control. when the emafe voltage regulator is turned off, its output stage is placed in high-impedance mode and thus can be forced by an external voltage source. 5.1.5 typical po wering schematics the sam4cm series supports 1.6v to 3.6v single-supply operation. restrictions on this range may apply depending on enabled features. refer to the section ?electrical characteristics?. note: figure 5-2 , figure 5-3 and figure 5-4 show simplified schematic s of the power section. vddcore 1.08v to 1.32v core logic, processors , memories and analog peripherals supply. vddin_afe 3.00v to 3.60v emafe regulator input. vdda 2.70 to 2.90v emafe regulator output (2.8v). emafe analog functions power supply input. table 5-1. power supply voltage ranges (continued)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 16 5.1.5.1 single supply operation figure 5-2 below shows a typical power supply scheme with a single power source. vddio, vddin, vddin_afe and vddbu are derived from the main power source (typically a 3.3v regulator output) while vddcore, vddpll, vddlcd, and vdda are fed by the embedded regulator outputs. figure 5-2. single supply operation notes: 1. internal lcd voltage regulator can be disabled to save its operating current. vddlcd must then be provided externally. sam4cm vddin vddout vddcore vddbu vddpll vddlcd vddio automatic power switch voltage regulator in out main supply vdda vddin_afe rc osc 32 khz xtal osc 32 khz backup region rtc, rtt, rstc, backup, reg, ... 10-bit adc, temp. sensor, voltage ref. lcd voltage regulator core voltage regulator lcd analog buffers + switch array vdda voltage regulator energy metering analog-front-end (1) 3.3v
17 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 5.1.5.2 single supply operation with backup battery figure 5-3 shows the single-supply operation schematic from figure 5-2 , improved by adding a backup capability. vddbu is supplied with a separate backup battery while vddio, vddin and vddin_afe are still connected to the main power source. note that the tmp1 and rtcout0 pins cannot be used in backup mode as they are referred to vddio which is not powered in this application case. figure 5-3. single supply operation with backup battery note: 1. example with the shdn pin used to control the main regulator enable pin. shdn defaults to vddbu at startup and when the device wakes up from a wake-up event (external pin, rtc alarm, etc.). when the device is in backup mode, shdn defaults to 0. sam4cm vddin vddout vddcore vddbu vddpll vddlcd vddio automatic power switch voltage regulator in out main supply vdda vddin_afe rc osc 32 khz xtal osc 32 khz backup region rtc, rtt, rstc, backup, reg, ... 10-bit adc, temp. sensor, voltage ref. lcd voltage regulator core voltage regulator lcd analog buffers + switch array vdda voltage regulator energy metering analog-front-end backup battery + - backup power supply (1.6v-3.6v) external wake-up signal shdn (1) fwup en
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 18 5.1.5.3 single power supply using one main battery and lcd contro ller in backup mode figure 5-4 below shows a typical power supply scheme that maintains vddbu, vddio, and vddlcd when entering backup mode. this is useful to enable the display and/or some supplementary wake-up sources in backup mode when the main voltage is not present. in this power supply scheme, the sam4cm can wake up both from an internal wake-up source, such as rtt, rtc and supply monitor, and from an external source, such as generic wake-up pins (wkupx), anti-tamper inputs (tmp0/1) or force wake-up (fwup). note: the vddio supply monitor only wakes up the device from backup mode on a negative-going vddio supply (as sys- tem alert). as a result, the supply moni tor cannot be used to wake up the device when the vddio supply is rising at power cycle. see the section ?supply controller (supc )? for more information on the vddio supply monitor. figure 5-4. single power supply using battery and lcd controller in backup mode notes: 1. the state output of the automatic power switch indicate s to the device that the main power is back and forces its wake-up. 2. rtcout0 signal is used to make a dynamic wake-up. wkupx pin is pulled-up with a low duty cycle to avoid battery discharge by permanent activation of the switch. sam4cm vddin vddout vddcore vddbu vddpll vddlcd vddio automatic power switch voltage regulator in out main supply vdda vddin_afe rc osc 32 khz xtal osc 32 khz backup region rtc, rtt, rstc, backup, reg, ... 10-bit adc, temp. sensor, voltage ref. lcd voltage regulator core voltage regulator lcd analog buffers + switch array vdda voltage regulator energy metering analog-front-end shdn fwup (1) en automatic power switch battery + - wkupx state state = 0 when main power is off rtcout0 (2)
19 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 5.1.5.4 wake-up, anti-tamper and rtcout0 pins in all power supply figures shown above, if generic wake -up pins other than wkup0/tmp0 are used either as a wake-up or a fast startup input, or as anti-tamper i nputs, vddio must be present. this also applies to the rtcout0 pin. 5.1.5.5 general-purpose io (gpio) state in low-power modes in dual-power supply schemes shown in figure 5-3 and figure 5-4 , where backup or wait mode must be used, configuration of the gpio lines is main tained in the same state as before entering backup or wait mode. thus, to avoid extra current consumption on the vddio power rail, the user must configure the gpios either as an input with pull-up or pull-down enabled, or as an output with low or high level to comply with external components. 5.1.5.6 default general-purpose ios (gpio) state after reset the reset state of the gpio li nes after reset is given in table 11-5, ?multiplexing on pio controller a (pioa)? , section 11-6 ?multiplexing on pio controller b (piob)? and table 11-7, ?multiplexing on pio controller c (pioc)? . for further details about the gpio and system lines, wa ke-up sources and wake-up time, an d typical power consumption in different low-power modes, refer to table 5-2, ?low-power mode configuration summary? .
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 20 5.2 clock system figure 5-5 illustrates the sam4cm clock syst em with single crystal operation: ? the 32 khz crystal oscillator can be the sour ce clock of the 8 mhz digital pll (plla) ? the 8 mhz clock can feed the high frequency pll (pllb) input ? the output of the pllb can be used as a main clock for both cores and the peripherals figure 5-5. global clock system plla pllb and divider /2 plladiv2 pllbdiv2 management controller main clock mainck control status moscsel xin xout xin32 xout32 slck xtalsel (supply controller) 0 1 0 1 3-20 mhz crystal or ceramic resonator oscillator embedded 4/8/12 mhz fast rc oscillator 32768 hz crystal oscillator embedded 32 khz rc oscillator srcb 1 0 clock generator slow clock power periph_clk[n] int slck mainck pllack prescaler / 1,/2,/3,/4,/8, /16,/32,/64 processor clock controller sleep mode master clock controller (pmc_mckr) peripherals clock controller (pmc_pcerx / pmc_pcr) pllbck core 0 (cm4-p0 clock system) core 0 (cm4-p0 clock system) core 1 (cm4-p1 clock system) core 1 (cm4-p1 clock system) pres css on/off on/off on/off periph_clk[n+1] periph_clk[n+2] slck mainck pllack prescaler divide by 1 to 16 master clock controller (pmc_mckr) pllbck cppres cpcss on/off periph_clk[m+2] int coprocessor clock cphclk where m is an index for the coprocessor system peripherals cpfclk coprocessor free running clock coprocessor systick clock cpsystick divider / 8 divider / 8 mck pmc_scer/scdr cpck= on/off where n is an index for the processor system peripherals on/off periph_clk[m] coprocessor bus master clock cpbmck processor clock hclk fclk processor free running clock processor systick clock systick processor bus master clock mck pmc_scer/scdr cpbmck= on/off coprocessor clock controller sleep mode pllb clock pllbck plla clock pllack 32 khz up to120 mhz 8 mhz
21 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 5.3 system state at power-up 5.3.1 device configuration after the first power-up at the first power-up, the sam4cm boots from the rom. the device c onfiguration is defined by sam-ba boot program. 5.3.2 device configuration after a power cycle when booting from flash memory after a power cycle of all the power supply rails, the system peripherals, such as the flash controller, the clock generator, the power management controller and the supply controller, are in the following states: ? slow clock (slck) source is the internal 32 kh z rc oscillator (32 khz crystal oscillator is disabled) ? main clock (mainck) source is set to the 4 mhz internal rc oscillator ? 3?20 mhz crystal oscillator and plls are disabled ? core brownout detector and core reset are enabled ? backup power-on-reset is enabled ? vddio supply monitor is disabled ? flash wait state (fws) bit in the eefc flash mode register is set to 0 ? core 0 cache controller (cmcc0) is enabled (only used if the application link add ress for the core 0 is 0x11000000) ? sub-system 1 is in the reset state and not clocked 5.3.3 device configuration after a reset after a reset or a wake-up from backup mode, the following system peripherals default to the same state as after a power cycle: ? main clock (mainck) source is set to the 4 mhz internal rc oscillator ? 3?20 mhz crystal oscillator and plls are disabled ? flash wait state (fws) bit in the eefc flash mode register is set to 0 ? core 0 cache controller (cmcc0) is enabled (only used if the application link add ress for the core 0 is 0x11000000) ? sub-system 1 is in the reset state and not clocked the states of the other peripherals are saved in the backup area managed by the supply controller as long as vddbu is maintained during device reset: ? slow clock (slck) source selectio n is written in supc_ cr.xtalsel. ? core brownout detector enable/disa ble is written in supc_mr.boddis. ? backup power-on-reset enable/disable is written in the supc_mr.bupporen. ? vddio supply monitor mode is written in the supc_smmr. 5.4 active mode active mode is the normal running mode, with the single core or the dual cores executing code. the system clock can be the fast rc oscillator, the ma in crystal oscillator or the plls. th e power management controller (pmc) can be used to adapt the frequency and to disable the peripheral clocks when unused.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 22 5.5 low-power modes the various low-power modes (backup, wait and sleep modes) of the sam4cm are described below. note that the segmented lcd controller can be used in all low-power modes. note: the wait for event instruction (wfe ) of the cortex-m4 core can be used to enter any of the low-power modes, however this may add complexity to the design of application state machines. this is due to the fact that the wfe instruction is associated with an event flag of the cortex core that cannot be ma naged by the software application. the event flag can be set by interrupts, a debug event or an ev ent signal from another processor. when an event occurs just before wfe execution, the processor takes it into account and does not enter low -power mode. atmel has made provision to avoid using the wfe instruction. the workar ounds to ease application design, including the use of the wfe instruction, are given in the following description of the low-power mode sequences. 5.5.1 backup mode the purpose of backup mode is to achieve the lowest possible power consumption in a system that executes periodic wake-ups to perform tasks but which does not require fast start-up time. the total current consumption is 0.5 a typical on vddbu. the supply controller, power-on reset, rtt, rtc, backup registers and the 32 khz oscillator (rc or crystal oscillator selected by software in the supply controller) are running. the regulator and the core supplies are off. the power-on-reset on vddbu can be deactivated by software. wake-up from backup mode can be done through the fo rce wake-up (fwup) pin, wkup0, wkup1 to wkup15 pins, the vddio supply monitor (sm) if vddio is suppl ied, or through an rtt or rtc wake-up event. wake-up pins multiplexed with anti-tampering functions are additional pos sible sources of a wake-up if an anti-tampering event is detected. the tmp0 pad is supplied by the ba ckup power supply (vddbu). tmp1 is supplied by vddio. the lcd controller can be used in backup mode. the purpose is to maintain the displayed message on the lcd display after entering backup mode. the current consumpt ion on vddin to maintain the lcd is 10 a typical. in case the vddio power supply is ma intained with vddbu when entering backup mode, it is up to the application to configure all pio lines in a stable and known state to avoid extra power consumption or possible current path with the input/output lines of the external on-board devices. 5.5.1.1 entering and exiting backup mode to enter backup mode, follow the steps in the sequence below: 1. depending on the application, set the pio lines in th e correct mode and configuration (input pull-up or pull- down, output low or high levels). 2. disable the main crystal oscillator (enabled by sam-ba boot if th e device is boot ing from rom). 3. configure pa30/pa31 (xin/xout) into pio mode depending on their use. 4. disable the jtag lines using the sfr1 register in matrix 0 (by default, internal pull-up or pull-down is disabled on jtag lines). 5. enable the rtt in 1 hz mode. 6. disable normal mode of the rtt (rtt will run in 1 hz mode). 7. disable the por backup if not needed. this increases power efficiency. 8. disable the core brownout detector. 9. select one of the following methods to complete the sequence: a. to enter backup mode using the vroff bit: ? write a 1 to the vroff bit of supc_cr. b. to enter backup mode using the wfe instruction: ? write a 1 to the sleepdeep bit of the cortex-m4 processor. ? execute the wfe instruction of the processor.
23 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 after this step, the core voltage regulator is shut down a nd the shdn pin goes low. the digital internal logic (cores, peripherals and memories) is not powered. the lcd c ontroller can be enabled if n eeded before entering backup mode. whether the vroff bit or the wfe instruction was used to enter backup mode, the system exits backup mode if one of the following enabled wake-up events occurs: ? wkup[0?13] pins ? force wake-up pin ? vddio supply monitor (if vddio is present, and vddi o supply falling) ? anti-tamper event detection ? rtc alarm ? rtt alarm after exiting backup mode, the device is in the reset stat e. only the configuration of the backup area peripherals remains unchanged. note that the device does not automatically enter backup mode if vddin is disconnected, or if it falls below minimum voltage. the shutdown pin (shdn) remains high in this case. for current consumption in backup mode, refer to the section ?electri cal characteristics?. 5.5.2 wait mode the purpose of wait mode is to achieve very low power consumption while maintaining the whole device in a powered state for a start-up time of less than 10 s. for current consumption in wait mode, refer to the section ?electrical characteristics?. in wait mode, the bus and peripheral clocks of sub-system 0 and sub-sy stem 1 (mck/cpbmck), the clocks of core 0 and core 1 (hclk/cphclk) are stopped when wait mode is entered (see section 5.5.2.1 ). however, the power supply of core, peripherals and memories are mainta ined using standby mode of the core voltage regulator. the sam4cm is able to handle external and internal event s in order to perform a wake-up. this is done by configuring the external wkupx lines as fast startup wake-up pins (refer to section 5.7 ?fast start-up? ). rtc alarm, rtt alarm and anti-tamper ev ents can also wake up the device. wait mode can be used together with flash in read-idle mode, standby mode or deep power-down mode to further reduce the current consumpti on. flash in read-idle mode provides a faster start-up; standby mode offers lower power consumption. for further details, see ?low-power wake-up time? in the section ?electrical characteristics?. 5.5.2.1 entering and exiting wait mode 1. stop sub-system 1. 2. select the 4/8/12 mhz fast rc oscillator as main clock (1) . 3. depending on the application, set the pio lines in th e correct mode and configuration (input pull-up or pull- down, output low or high level). 4. disable the main crystal oscilla tor (enabled by sam-ba boot if device is booting from rom). 5. configure pa30/pa31 (xin/xout) into pio mode according to their use. 6. disable the jtag lines using the sfr1 register in matrix 0 (by default, internal pull-up or pull-down is disabled on jtag lines). 7. set the flpm field in the pmc fast startup mode register (pmc_fsmr) (2) . 8. set the flash wait state (fws) bit in the eefc flash mode register to 0. 9. select one of the following methods to complete the sequence: a. to enter wait mode using the waitmode bit: ? set the waitmode bit to 1 in the pmc main oscillator register (ckgr_mor).
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 24 ? wait for master clock ready mckrdy = 1 in the pmc status register (pmc_sr). b. to enter wait mode using the wfe instruction: ? select the 4/8/12 mhz fast rc oscillator as main clock. ? set the flpm field in the pmc fast startup mode register (pmc_fsmr). ? set flash wait state at 0. ? set the lpm bit in the pmc fast startup mode register (pmc_fsmr). ? write a 0 to the sleepdeep bit of the cortex-m4 processor. ? execute the wait-for-event (wfe) instruction of the processor. notes: 1. any frequency can be chosen. the 12 mhz frequency will pr ovide a faster start-up compared to the 4 mhz, but with the increased current consumption (in the a range). see electr ical characteristics of the product. 2. depending on the flash low-power mode (flpm) value, the flash enters three different modes: ? if flpm = 0, the flash enters stand-by mode (low consumption) ? if flpm = 1, the flash enters deep power-down mode (extra low consumption) ? if flpm = 2, the flash enters idle mode. memory is ready for read access whether the waitmode bit or the wfe instruction was used to enter wait mode, the system exits wait mode if one of the following enabled wake-up events occurs: ? wkup[0-15] pins in fast wake-up mode ? anti-tamper event detection ? rtc alarm ? rtt alarm after exiting wait mode, the pio cont roller has the same configuration stat e as before entering wait mode. the sam4cm is clocked back to the rc osc illator frequency which was used before entering wait mode. the core will start fetching from flash at this frequency. depending on the configuration of the flash low-power mode (flpm) bits used to enter wait mode, the application has to reconfigure it back to read-idle mode. 5.5.3 sleep mode the purpose of sleep mode is to optimize power consumption of the device versus response time. in this mode, only the core clocks of cm4p0 and/or cm4p1 ar e stopped. some of the peripheral clocks can be enabled depending on the application needs. the current consumptio n in this mode is application dependent. this mode is entered using wait for interrupt (wfi) or wait for event (wfe) instruct ions of the cortex-m4. the processor can be awakened from an interrupt if the wfi instruction of the cortex-m4 is used to enter sleep mode, or from a wake-up event if the wfe instruction is us ed. the wfi instruction can also be used to enter sleep mode with the sleeponexit bit set to 1 in the system control register (scb_scr) of the cortex-m. if the sleeponexit bit of the scb_scr is se t to 1, when the processor comple tes the execution of an exception handler, it returns to thread mode and immediatel y enters sleep mode. this mechanism can be used in applications that require the processor to run only when an exception occurs. setting the sleeponexit bit to 1 enables an interrupt-driven application in order to avoid returning to an empty main application.
25 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 5.5.4 low-power mode summary table the modes detailed above are the main low-power modes. table 5-2 below provides a configuration summary of the low-power modes. for more information on power consumption, refer to the section ?electrical characteristics?. notes: 1. when considering wake-up time, the time required to start the pll is not taken into account. once started, the device w orks either from the 4, 8 or 12 mhz fa st rc oscillator. the user has to add the pll start-up time if it is needed in the system. the wake-up time is defined as the time taken fo r wake-up until the first instruction is fetched. 2. in this mode, the core is supplied and not clocked but some peripherals can be clocked. table 5-2. low-power mode configuration summary mode supc, 32 khz oscillator rtc, rtt backup registers por (backup region) core regulator / lcd regulator core 0/1 memory peripherals mode entry (7) potential wake-up sources core at wake-up pio state in low- power mode pio state at wake-up wake-up time (1) backup mode on off/off off / off (not powered) vroff bit = 1 or sleepdeep = 1 + wfe - fwup pin - wkup0-15 pins (5) - supply monitor - anti-tamper inputs (5) - rtc or rtt alarm reset previous state saved reset state (8) < 1.5 ms backup mode with lcd on off/on off / off (not powered) vroff bit = 1 or sleepdeep = 1 + wfe - fwup pin - wkup0-15 pins (5) - supply monitor - anti-tamper inputs (5) - rtc or rtt alarm reset previous state saved unchanged (lcd pins)/ inputs with pull ups < 1.5 ms wait mode flash in standby mode (6) on on/ (4) core 0 and 1, memories and peripherals: powered, but not clocked waitmode = 1 + flpm = 0 or sleepdeep = 0 + lpm = 1 + flpm = 0 + wfe any event from: - fast start-up through wkup0-15 pins - anti-tamper inputs (5) - rtc or rtt alarm clocked back previous state saved unchanged < 10 s wait mode flash in deep power- down mode (6) on on/ (4) core 0 and 1, memories and peripherals: powered, but not clocked waitmode = 1 + flpm = 1 or sleepdeep = 0 + lpm = 1 + flpm = 1 + wfe any event from: - fast start-up through wkup0-15 pins - anti-tamper inputs (5) - rtc or rtt alarm clocked back previous state saved unchanged < 75 s sleep mode on on/ (4) core 0 and/or core 1: powered (not clocked) (2) sleepdeep = 0 + lpm = 0 + wfe or wfi entry mode = wfi any enabled interrupts; entry mode = wfe any enabled event: - fast start-up through wkup0-15 pins - anti-tamper inputs (5) - rtc or rtt alarm clocked back previous state saved unchanged (3)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 26 3. depends on mck frequency. 4. lcd voltage regulator can be off if vddlcd is supplied exte rnally thus saving current c onsumption of the lcd voltage regulator. 5. refer to table 3-1, ?signal description list? . some anti-tamper pin pads are vddio powered. 6. fast rc oscillator set to 4 mhz frequency. 7. refer to the note in section 5.5 ?low-power modes? . 8. see pio controller multiplexing tables in section 11.4 ?peripheral signal multiplexing on i/o lines? . 5.6 wake-up sources wake-up events allow the device to exit backup mode. when a wake-up event is dete cted, the supply controller performs a sequence which automat ically reenables the core power supply and all digital logic. 5.7 fast start-up the sam4cm allows the processor to restart in a few microseconds while the processor is in wait mode or in sleep mode. a fast start-up occurs upon detection of one of the wake-up inputs. the fast restart circuitry is fully asynchronous and provides a fast start-up signal to the power management controller. as soon as the fast start-up signal is asserted, the pmc automatica lly restarts the embedded 4/8/12 mhz fast rc oscillator, switches th e master clock on this 4 mhz clock and re-enables the processor clock.
27 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 6. input/output lines the sam4cm has two types of input/output (i/o) line s?general-purpose i/os (gpio) and system i/os. gpios have alternate function ality due to multiplexing capabilities of the pio controllers. the same pio line can be used whether in i/o mode or by the multiple xed peripheral. system i/os include pins such as test pins, oscillators, erase or analog inputs. 6.1 general-purpose i/o lines general-purpose i/o (gpio) lines ar e managed by pio controllers. all i/o s have several input or output modes such as pull-up or pull-down, input schmitt triggers, multi-drive (open-drain), glitch filters, debouncing or input change interrupt. programming of these modes is performed independently for each i/o line through the pio controller user interface. for more de tails, refer to the ?par allel input/output (pio) co ntroller? section of this datasheet. the input/output buffers of the pio lines are suppli ed through vddio power supply rail when used as gpios. when used as extra functions such as lcd or analog m odes, gpio lines have either vddlcd or vddin voltage range. each i/o line embeds an odt (on-die termination), shown in figure 6-1 below. odt consists of an internal series resistor termination scheme for im pedance matching between the driver output (sam4cm) and the pcb trace impedance preventing signal refl ection. the series resistor helps to reduce ios switching current (di/dt) thereby reducing emi. it also decreases overshoot and unders hoot (ringing) due to inductance of interconnect between devices or between boards. finally, odt hel ps diminish signal integrity issues. figure 6-1. on-die termination pcb tr ace z0 ~ 50 ohm s receiver s am4 driver with rodt zout ~ 10 ohms z0 ~ zout + rodt odt 36 ohms ty p.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28 6.2 system i/o lines system i/o lines are pins used by oscillators, test mode, rese t and jtag and other fe atures. table 6-1 describes the sam4cm system i/o lines shared wit h pio lines. these pins are software -configurable as general-purpose i/o or system pins. at start-up, the default function of these pins is always used. notes: 1. if pc9 is used as pio input in us er applications, a low level must be ensured at start-up to prevent flash erase before the user application sets pc9 into pio mode. 2. refer to ?3 to 20 mhz crystal oscillator? in the section ?power management controller (pmc)?. 6.2.1 serial wire jtag debug port (swj-dp) and serial wire debug port (sw-dp) pins the swj-dp pins are tck/swclk, tms/swdio, tdo/ traceswo, tdi and commonl y provided on a standard 20-pin jtag connector defined by arm. for more deta ils about voltage reference and reset state, refer to table 11-6, ?multiplexing on pio controller b (piob)? . at start-up, swj-dp pins are configured in swj-dp mode to allow connection with debugging probe. refer to the ?debug and test? section of this datasheet. swj-dp pins can be used as standard i/os to provide users with more general input/output pins when the debug port is not needed in the end application. mode sele ction between swj-dp mode (system io mode) and general io mode is performed through the ahb matrix special func tion registers (matrix_sfr). configuration of the pad for pull-up, triggers, debouncing and glitch filters is possible regardless of the mode. the jtagsel pin is used to select the jtag boundary scan when asserted at a high level. it integrates a permanent pull-down resistor of about 15 k to gnd, so that it can be le ft unconnected for normal operations. by default, the jtag debug port is active. if the debugger host wants to switch to the serial wire debug port, it must provide a dedicated jtag sequence on tms/swdi o and tck/swclk which disables the jtag-dp and enables the sw-dp. when the serial wire debug port is active, tdo/traceswo can be used for trace. the asynchronous trace output (traceswo) is multiplexe d with tdo. so the asynchronous trace can only be used with sw-dp, not jtag-dp. for more information about sw-dp and jtag -dp switching, refer to the ?debug and test? section of this datasheet. the sw-dp/swj-dp pins are used for debug access to both cores. 6.3 tst pin the tst pin is used for jtag boundary scan manufacturing test or fast flash programming mode of the sam4cm series. for details on entering fast programm ing mode, see the ?fast fl ash programming interface (ffpi)? section of this datasheet. for more information on the manufacturing and test modes, refer to the ?debug and test? section of this datasheet. table 6-1. system i/o configuration pin list system_io bit number default function after reset other function constraints for normal start configuration 0 tdi pb0 ? in matrix user interface registers (refer to the system i/o configuration register in the ?bus matrix? section of this datasheet) 1 tdo/traceswo pb1 ? 2 tms/swdio pb2 ? 3 tck/swclk pb3 ? 4 erase pc9 low level at start-up (1) ?p a 3 1x i n ? (2) ?p a 3 0 x o u t?
29 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 6.4 nrst pin the nrst pin is bidirectional. it is handled by the on-chi p reset controller and can be driven low to provide a reset signal to the external components, or asserted low externally to reset the microcontroller. it resets the core and the peripherals, with the exception of t he backup region (rtc, rtt and supply controller). there is no constraint on the length of the reset pulse, and the reset controller can guarantee a minimum pulse length. the nrst pin integrates a permanent pull-up resistor to vddio of about 100 k . by default, the nrst pin is configured as an input. 6.5 tmpx pins: anti-tamper pins anti-tamper pins detect intrusion?for example, into a smart meter case. upon detection through a tamper switch, automatic, asynchronous and immediate clear of registers in the backup area, and time stamping in the rtc are performed. anti-tamper pins can be used in all modes. date and number of tampering events are stored automatically. anti-tampering events c an be programmed so that half of th e general-purpose backup registers (gpbr) are erased automatically. tmp1 signal is referred to vddio, meaning t hat it is effective only if vddio is supplied, whereas tmp0 is in the vddbu domain. 6.6 rtcout0 pin the rtcout0 pin shared in the pio (supplied by vddio) can be used to generate waveforms from the rtc in order to take advantage of the rtc inherent prescalers while the rtc is the only powered circuitry (low-power mode, backup mode) or in any active mode. entering backup or low-power operating modes does not affect the waveform generation out puts (vddio still needs to be supplied). anti-tampering pi n detection can be synchronized with this signal. note: to use the rtcout0 signal during application developm ent using jtag-ice interface, the programmer must use serial wire debug (swd) mode. in this case, the tdo pi n is not used as a jtag signal by the ice interface. 6.7 shutdown (shdn) pin the shdn pin designates the backup mo de of operation. when the device is in backup mode, shdn = 0. in any other mode, shdn = 1 (vddbu). this pin is designed to control the enable pin of the main external voltage regulator. when the device enters backup mode, the shdn pi n disables the external voltage regulator and, upon the wake-up event, it re-enables the voltage regulator. the shdn pin is asserted low when the vroff bit in th e supply controller control register (supc_cr) is set to 1. 6.8 force wake-up (fwup) pin the fwup pin can be used as a wake-up source in all low-power modes as it is supplied by vddbu. 6.9 erase pin the erase pin is used to reinitialize th e flash content (and some of its nvm bi ts) to an erased state (all bits read as logic level 1). the erase pin integrates a pull-down resistor of about 100 k into gnd, so that it can be left unconnected for normal operations. this pin is debounced by slck to improve the glitch tolerance. when the erase pin is tied high during less than 100 ms, it is not taken into account. the pin must be ti ed high during more than 220 ms to perform a flash erase operation. the erase pin is a system i/o pin and can be used as a standard i/o. at start-up, the erase pin is not configured as a pio pin. if the erase pin is used as a standard i/o, the start-up level of this pin must be low to prevent unwanted erasing. refer to section 11.3 ?apb/ahb bridge? . if the erase pin is used as a standard i/o output, asserting the pin to low does not erase the flash.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30 to avoid unexpected erase at power-up, a minimum er ase pin assertion time is required. this time is defined in the ac flash characteristics in the section ?electrical characteristics?. the erase operation is not performed when the system is in wait mode with the flas h in deep power-down mode. to make sure that the erase operation is performed afte r power-up, the system must not reconfigure the erase pin as gpio or enter wait mode wit h flash in deep power-down mode be fore the erase pin assertion time has elapsed. with the following sequence, in any case, the erase operation is performed: 1. assert the erase pin (high). 2. assert the nrst pin (low). 3. power cycle the device. 4. maintain the erase pin high for at least the minimum assertion time.
31 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 7. product mapping and peripheral access figure 7-1 shows the default memory mapping of the arm cortex-m core. figure 7-1. cortex -m memory mapping code sram external ram external device peripherals 0x00000000 0x1fffffff 0x20000000 0x3fffffff 0x40000000 0x5fffffff 0x60000000 0x9fffffff system level 0xa0000000 0xdfffffff 0xe0000000 0xffffffff mainly used for program code. also provides exception vector table after power up mainly used as static ram mainly used as peripherals mainly used as external memory mainly used as external peripherals private peripherals including build-in interrupt controller (nvic), mpu control registers, and debug components
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32 figure 7-2. sam4cm16/8 memory mapping of code and sram area notes: 1. boot memory for core 0. 2. boot memory for core 1 @ 0x00000000. code 0x00000000 intern al flash (code - non-cached) 0x01000000 intern a l rom 0x02000000 ebi chip select 0 (code - non-cached) ebi chip select 0 (code - cached) ebi chip select 1 (code - cached) ebi chip select 2 (code - cached) ebi chip select 3 (code - cached) ebi chip select 1 (code - non-cached) ebi chip select 2 (code - non-cached) ebi chip select 3 (code - non-cached) 0x03000000 0x04000000 0x05000000 0x06000000 0x07000000 0x10000000 intern al flash (code - cached) 0x11000000 0x12000000 0x13000000 0x14000000 0x15000000 0x16000000 0x17000000 0x1fffffff intern al sram sram0 0x20000000 0x20080000 sram2 0x20100000 cpkcc rom 0x20180000 res erved 0x20190000 cpkcc sram 0x20191000 res erved 0x20192000 undefined (ab ort) 0x20200000 0x3fffffff offset id peripher al block undefined (ab ort) undefined (ab ort) undefined (ab ort) undefined (ab ort) address memory space code 0x00000000 intern al sram 0x20000000 peripher als 0x40000000 extern al sram 0x60000000 extern a l devices 0xa0000000 cortex-m priv a te peripher al bus res erved 0xe0000000 0xe0100000 0xffffffff sram1 (2) boot memory (1) (code - non-cached)
33 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 7-3. sam4cm32 memory mapping of code and sram area notes: 1. boot memory for core 0. 2. boot memory for core 1 @ 0x00000000. code boot memory (1) (code - non-cached) 0x00000000 intern al flash - plane 1 (code - non-cached) 0x01100000 intern al flash - plane 0 (code - non-cached) 0x01000000 intern a l rom 0x02000000 ebi chip select 0 (code - non-cached) ebi chip select 0 (code - cached) ebi chip select 1 (code - cached) ebi chip select 2 (code - cached) ebi chip select 3 (code - cached) ebi chip select 1 (code - non-cached) ebi chip select 2 (code - non-cached) ebi chip select 3 (code - non-cached) 0x03000000 0x04000000 0x05000000 0x06000000 0x07000000 0x10000000 intern al flash (code - cached) 0x11000000 0x12000000 0x13000000 0x14000000 0x15000000 0x16000000 0x17000000 0x1fffffff intern al sram sram0 0x20000000 sram1 (2) 0x20080000 sram2 0x20100000 cpkcc rom 0x20180000 res erved 0x20190000 cpkcc sram 0x20191000 res erved 0x20192000 undefined (ab ort) 0x20200000 0x3fffffff offset id peripher al block undefined (ab ort) undefined (ab ort) undefined (ab ort) undefined (ab ort) address memory space code 0x00000000 intern al sram 0x20000000 peripher als 0x40000000 extern al sram 0x60000000 extern a l devices 0xa0000000 cortex-m priv a te peripher al bus res erved 0xe0000000 0xe0100000 0xffffffff
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34 in figure 7-2 and figure 7-3 above, ?code? means ?program code over i-code bus? and ?program data over d- code bus?. sram1 can be seen at the address 0x20080000 (through s-bus) and the address 0x00000000 (through i/d bus) for core1. instruction fetch from core 1 to the sram address range is possible but leads to reduced performance due to the fact that instructions and read/write data go through the system bus (s-bus). maximum performance for core 1 (metrology core) is obtained by mapping the inst ruction code to the address 0x00000000 (sram1 through i/d-code) and read/write data from the address 0x20100000 (sram2 through s-bus). for core 0 (application core), maximum performance is achieved when the instruction code is mapped to the flash address and read/write data is mapped into sram0. each core can access the following memories and peripherals: ? core 0 (application core): ? all internal memories ? external memories or memory devices mapped on smc 0 or smc 1 ? all internal peripherals ? core 1 (metrology/coprocessor core): ? all internal memories ? external memories or memory devices mapped on smc 0 or smc 1 ? all internal peripherals note that peripheral dma 0 on matrix 0 cannot access sram1 or sram2, peripheral dma 1 on matrix 1 cannot access sram0, sram2 or sram0 can be th e data ram for inter- core communication. if core 1 is not to be used (clock stopped and reset active), all the peripherals, sram1 and sram2 of the sub- system 1 can be used by the application core 0) as long as the peripheral bus clock and reset are configured. detailed memory mapping and memory access versus matrix masters/slaves are given in the ?bus matrix (matrix)? section of this datasheet.
35 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 7-4. sam4cm16/8 memory mapping of the peripherals area address memory space code 0x00000000 intern al sram 0x20000000 peripher als 0x40000000 extern al sram 0x60000000 extern a l devices 0xa0000000 0xe0000000 0xe0100000 0xffffffff peripher als aes 36 0x40000000 res erved 0x40004000 spi0 21 0x40008000 res erved 0x4000c000 tc0 tc0 0x40010000 23 tc0 tc1 +0x40 24 tc0 tc2 +0x80 25 tc3 0x40014000 tc1 tc4 +0x40 27 tc1 tc5 +0x80 28 twi0 19 0x40018000 twi1 20 0x4001c000 res erved 0x40020000 us art0 0x40024000 14 us art1 15 0x40028000 us art2 16 0x4002c000 us art3 17 0x40030000 res erved 0x40034000 adc 29 0x40038000 slcdc 32 0x4003c000 cpkcc 35 0x40040000 icm 34 0x40044000 trng 33 0x40048000 ipc0 31 0x4004c000 res erved 0x40050000 cmcc0 0x4007c000 res erved 0x40080000 system controller 0x400e0000 res erved 0x400e4000 res erved 0x48000000 uart1 38 0x48004000 0x48004000 pwm 41 0x48008000 pioc 37 0x4800c000 matrix1 0x48010000 ipc1 39 0x48014000 cmcc1 0x48018000 smc1 43 0x4801c000 res erved 0x48020000 0x5fffffff system controller smc0 10 0x400e0000 matrix0 0x400e0200 pmc 5 0x400e0400 uart0 8 0x400e0600 chipid 0x400e0740 res erved 0x400e0800 efc 6 0x400e0a00 0x400e0c00 pioa 11 0x400e0e00 piob 12 0x400e1000 res erved 0x400e1200 sysc rstc 0x400e1400 1 sysc supc +0x10 sysc rtt +0x30 3 sysc wdt +0x50 4 sysc rtc +0x60 2 sysc gpbr +0x90 res erved 0x400e1600 0x400e4000 cortex-m priv ate peripher al bus res erved 26 tc1 res erved
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36 figure 7-5. sam4cm32 memory mapping of the peripherals area address memory space code 0x00000000 intern al sram 0x20000000 peripher als 0x40000000 extern al sram 0x60000000 extern a l devices 0xa0000000 0xe0000000 0xe0100000 0xffffffff peripher als aes 36 0x40000000 res erved 0x40004000 spi0 21 0x40008000 res erved 0x4000c000 tc0 tc0 0x40010000 23 tc0 tc1 +0x40 24 tc0 tc2 +0x80 25 tc3 0x40014000 tc1 tc4 +0x40 27 tc1 tc5 +0x80 28 twi0 19 0x40018000 twi1 20 0x4001c000 res erved 0x40020000 us art0 0x40024000 14 us art1 15 0x40028000 us art2 16 0x4002c000 us art3 17 0x40030000 res erved 0x40034000 adc 29 0x40038000 slcdc 32 0x4003c000 cpkcc 35 0x40040000 icm 34 0x40044000 trng 33 0x40048000 ipc0 31 0x4004c000 res erved 0x40050000 cmcc0 0x4007c000 res erved 0x40080000 system controller 0x400e0000 res erved 0x400e4000 res erved 0x48000000 uart1 38 0x48004000 0x48004000 pwm 41 0x48008000 pioc 37 0x4800c000 matrix1 0x48010000 ipc1 39 0x48014000 cmcc1 0x48018000 smc1 43 0x4801c000 res erved 0x48020000 0x5fffffff system controller smc0 10 0x400e0000 matrix0 0x400e0200 pmc 5 0x400e0400 uart0 8 0x400e0600 chipid 0x400e0740 res erved 0x400e0800 efc0 6 0x400e0a00 efc1 0x400e0c00 pioa 11 0x400e0e00 piob 12 0x400e1000 res erved 0x400e1200 sysc rstc 0x400e1400 1 sysc supc +0x10 sysc rtt +0x30 3 sysc wdt +0x50 4 sysc rtc +0x60 2 sysc gpbr +0x90 res erved 0x400e1600 0x400e4000 cortex-m priv ate peripher al bus res erved 26 tc1 7
37 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 7-6. sam4cm32/16/8 memory mapping of external sram and external devices area address memory space code 0x00000000 intern al sram 0x20000000 peripher als 0x40000000 extern al sram 0x60000000 extern a l devices 0xa0000000 cortex-m priv a te peripher al bus res erved 0xe0000000 0xe0100000 0xffffffff extern al sram ebi chip select 0 0x60000000 ebi chip select 1 0x61000000 ebi chip select 2 0x62000000 ebi chip select 3 0x63000000 0x64000000 0x9fffffff extern a l devices ebi chip select 0 (extern a l device) 0xa0000000 ebi chip select 1 (extern a l device) 0xa1000000 ebi chip select 2 (extern a l device) 0xa2000000 ebi chip select 3 (extern a l device) 0xa3000000 0xa4000000 0xdfffffff undefined (ab ort) undefined (ab ort) offset id peripher al block
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38 8. memories the memory map shown in figure 7-2, ?sam4cm16/8 memory mapping of code and sram area? is common to both cortex-m4 processors with the exception of the ?boot memory? block. for more information on boot memory, refer to section 8.1.5 ?boot strategy? . each processor uses its ow n arm private peripheral bus (ppb) for the nvic and other system functions. 8.1 embedded memories 8.1.1 internal sram the sam4cm embeds a total of up to 304 kbytes hi gh-speed sram with zero wait state access time. sram0 on matrix0 is up to 256 kbytes. it is dedicated to the application pr ocessor (cm4p0) or other peripherals on matrix0 but can be identified and used by masters on matrix1. sram1 on matrix1 is up to 32 kbytes. it is mainly dedicate d to be the code region of the cm4p1 processor but can be identified and used by matrix0. sram2 on matrix1 is up to 16 kbytes. it is mainly dedica ted to be the data region of the cm4p1 processor or other peripherals on matrix1 but can be identifi ed and used by masters on matrix0. refer to the section ?bus matrix (matri x)? of this datasheet for more details. if the cm4p1 processor is in the reset state and not used, the application core may use it. the sram is located in the bit band region. the bit band alias region is from 0x2200 0000 to 0x23ff_ffff. 8.1.2 system rom the sam4cm embeds an internal rom for the master processor (cm4p0), which contains the sam boot assistant (sam-ba ? ), in application programming routines (iap), and fast flash programming interface (ffpi). the rom is always mapped at the address 0x02000000. 8.1.3 cpkcc rom the rom contains a cryptographic library using the cpkcc cryptographic accelerator peripheral (cpkcc) to provide support for rive st shamir adleman (rsa), elliptic curve crypt ography (ecc), digita l signature algorithm (dsa) and elliptic curve digita l signature algorithm (ecdsa). 8.1.4 embedded flash 8.1.4.1 flash overview the embedded flash is the boot memory for the cortex-m 4 core 0 (cm4p0). the flash memory can be accessed through the cache memory controller (cmcc0) of the cm4p 0 and can also be identified by the cortex-m4f core 1 (cm4p1) through its cache memory controller (cmcc1). the sam4cm32 features a dual-plane flash to program or erase a memory plane while reading from the other plane. the dual-plane capability also provides the du al boot scheme. the benefit of the dual plane and the dual boot is that the firmware can be upgraded while the main app lication is running and that it is possible to switch to the new firmware in the other plane. figure 8-1 below shows the operating principle of firmware upgrade by using the dual bank/dual boot.
39 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 8-1. dual bank and dual boot firmware upgrade the memory plane is organized in sector s. each sector has a size of 64 kbyt es. the first sector of 64 kbytes is divided into 3 smaller sectors. the three smaller sectors are organized in 2 sectors of 8 kbytes and 1 sector of 48 kbytes. refer to figure 8-2 below. the flash memory has built-in error code correction prov iding 2-bit error detection and 1-bit correction per 128 bits. figure 8-2. memory plane organization bank 1 v1.0 bank 2 v1.1 bank 1 v1.0 bank 2 corrupt bank 1 v1.0 bank 2 v1.1 reset vector reset vector reset vector normal operation from bank 1 while simultaneously remotely programming bank 2 power or comms failure cause bank 2 program fail while bank 1 continues to operate and requests retransmission wired / wireless stream reprogramming successful, device now executes from bank 2,bank 1 available for next update small sector 0 8 kb ytes small sector 1 8 kb ytes larger sector 48 kb ytes sector 1 64 kb ytes 64 kb ytes sector n sector 0 sector s ize sector name
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40 each sector is organized in pages of 512 bytes. for sector 0: ? the small sector 0 has 16 pages of 512 bytes, 8 kbytes in total ? the small sector 1 has 16 pages of 512 bytes, 8 kbytes in total ? the larger sector has 96 pages of 512 bytes, 48 kbytes in total from sector 1 to n: the rest of the array is composed of 64-kbyte sectors where each sector comprises 128 pages of 512 bytes. refer to figure 8-3, ?flash sector organization? below. figure 8-3. flash sector organization table 8-1. sam4cm flash size device flash (kbytes) sam4cm8 512 sam4cm16 1024 sam4cm32 2048 (2 1024) sector 0 sector n small sector 0 small sector 1 larger sector a sector s ize is 64 kb ytes 16 pages of 512 b ytes 16 pages of 512 b ytes 96 pages of 512 b ytes 128 pages of 512 b ytes
41 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 8-4 and figure 8-4 illustrates the organization of the flash depending on its size. figure 8-4. flash size the following erase commands can be used depending on the sector size: ? 8 kbyte small sector ? erase and write page (ewp) ? erase and write page and lock (ewpl) ? erase sector (es) with farg set to a page number in the sector to erase ? erase pages (epa) with farg [1:0] = 0 to erase four pages or farg [1:0] = 1 to erase eight pages. farg [1:0] = 2 and farg [1:0] = 3 must not be used. ? 48 kbyte and 64 kbyte sectors ? one block of 8 pages inside any sector, with the command erase pages (epa) with farg[1:0] = 1 ? one block of 16 pages inside any sector, with the command erase pages (epa) and farg[1:0] = 2 ? one block of 32 pages inside any sector, with the command erase pages (epa) and farg[1:0] = 3 ? one sector with the command erase sector (es) an d farg set to a page number in the sector to erase ? entire memory plane ? the entire flash, with the command erase all (ea) 8.1.4.2 enhanced embedd ed flash controller the enhanced embedded flash controller manages accesses performed by masters of the system. it enables reading the flash and writing the write buffer. it al so contains a user interface, mapped on the apb. the enhanced embedded flash controller ensures the interface of the flash block. it manages the programming, erasing, locking and unlocking sequences of the flash using the full set of commands. one of the commands return s the embedded flash descripto r definition that informs the system about the flash organization, thus making the software generic. 2 * 8 kb ytes 1 * 48 kb ytes 15 * 64 kb ytes 2 * 8 kb ytes 1 * 48 kb ytes 7 * 64 kb ytes flash 1 mb ytes 2 * 8 kb ytes 1 * 48 kb ytes 15 * 64 kb ytes 2 * 8 kb ytes 1 * 48 kb ytes 15 * 64 kb ytes flash 2 mb ytes plane 0 plane 1 flash 512 kb ytes
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42 8.1.4.3 flash speed the user must set the number of wait states depending on the frequency used on the sam4cm. for more details, refer to ?embedded flash? of the section ?electrical characteristics?. 8.1.4.4 lock regions several lock bits are used to protect write and erase oper ations on lock regions. a lock region is composed of several consecutive pages, and each lock region has its associated lock bit. the lock bits are software programmable through the ee fc user interface. the command ?set lock bit? enables the protection. the command ?clear lock bit? unlocks the lock region. asserting the erase pin clears the lock bits, thus unlockin g the entire flash. 8.1.4.5 security bit the sam4cm features a security bit based on a specific general-purpose nvm bit (gpnvm bit 0). when the security is enabled, any access to the flash, sram, core registers and inter nal peripherals, either through the sw- dp/jtag-dp interface or through t he fast flash programming interface, is forbidden. this ensures the confidentiality of the code programmed in the flash. this security bit can only be enabled through the command ?set general-purpose nvm bit 0? of the eefc user interface. disabling the security bit ca n only be achieved by asserting the erase pin at 1, and after a full flash erase is performed. when the security bit is deactivated, all accesses to the flash, sr am, core registers, internal peripherals are permitted. 8.1.4.6 unique identifier each device integrates its own 128-bit unique identifier. these bits are factory-configured and cannot be changed by the user. the erase pin has no effect on the unique identifier. 8.1.4.7 user signature the memory has one additional reprogrammable page that can be used as page signature by the user. it is accessible through specific modes, for erase, write and read operations. erase pin assertion will not erase the user signature page. 8.1.4.8 fast flash programming interface the fast flash programming interface allows programming the device through either a serial jtag interface or through a multiplexed fully-handshaked parallel port. it allows gang programming with market-standard industrial programmers. the ffpi supports read, page program, page erase, full erase, lock, unlock and protect commands. 8.1.4.9 sam-ba boot the sam-ba boot is a default boot program for the ma ster processor (cm4p0) which provides an easy way to program in-situ the on-chip flash memory. the sam-ba boot assistan t supports serial commu nication via the uart0. the sam-ba boot provides an interface with sam-ba graphic user interface (gui). the sam-ba boot is in rom and is mapped in flas h at address 0x0 when gpnvm bit 1 is set to 0. table 8-2. lock bit number product number of lock bits lock region size sam4cm32 256 (128 + 128) 8 kbytes sam4cm16 128 8 kbytes sam4cm8 64 8 kbytes
43 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 8.1.4.10 gpnvm bits the sam4cm features two (sam4cm16/sam4cm8) or three (sam4cm32) gpnvm bits. these bits can be cleared or set respectively through the commands ?clear gpnvm bit? and ?set gpnvm bit? of the eefc user interface (see the ?eefc flash command r egister? section of this datasheet). 8.1.5 boot strategy figure 8-5 below shows a load view of the memory at boot time. figure 8-5. simplified load view at boot time note: matrices, ahb and apb bridges are not represented. 8.1.5.1 application core (core 0) boot process the application processor (cm4p0) always boots at the address 0x0. to ensure maximum boot possibilities, the memory layout can be changed using a general-purpose nvm (gpnvm) bit. a gpnvm bit is used to boot either on the rom (default) or from the flash. the gpnvm bit can be cleared or set through the commands ?clear general-purpose nvm bit? and ?set general-purpose nvm bit? of the eefc user interface. setting gpnvm bit 1 selects the boot from flash whereas clearing this bit selects the boot from rom. asserting erase clears the gpnvm bit 1 and thus selects the boot from the rom by default. 8.1.5.2 metrology/coprocessor core (core 1) boot process after reset, the sub-system 1 is hold in reset and with no clock. it is up to the master application (core 0 application) running on the core 0 to enable the sub-syst em 1. then the application code can be downloaded into the cm4p1 boot memory (sram1), and cm4p0 can afte rwards de-assert the cm4p1 reset line. the secondary processor (cm4p1) always ident ifies sram1 as ?boot memory?. table 8-3. general-purpose nonvolatile memory bits gpnvm bit function 0 security bit 1 boot mode selection 2 memory plane boot selection (plane 0 or plane 1) (sam4cm32 only) s ram0 s ram1 core 0 application core (cortex-m4) icode / dcode b us s -bus icode / dcode b us s -bus s ram2 fl ash core 0 application core1 applic a tion (binary img.) clock & re s et control core 1 metrology core (cortex-m4f) sub-system 0 sub-system 1 mpu nvic fpu nvic
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 44 8.1.5.3 sub-system 1 startup sequence after the core 0 is booted from flash, the co re 0 application must perform the following steps: 1. enable core 1 system clock (bus and peripherals). 2. enable core 1 clock. 3. release core 1 system reset (bus and peripherals). 4. enable sram1 and sram2 clock. 5. copy core 1 application from flash into sram1. 6. release core 1 reset. after step 6, the core 1 boots from sram1 memory. pseudo-code: 1- // enable coprocessor bus master clock (pmc_scer.cpbmck). 2- // enable coprocessor clocks (pmc_scer.cpck). // set coprocessor clock prescaler and source (pmc_mckr.cppres). // choose coprocessor main clock source (pmc_mckr.cpcss). 3- // release coprocessor peripheral reset (rstc_cpmr.cperen). 4- // enable core 1 sram1 and sram2 memories (pmc_pcer.pid42). 5- // copy core 1 application code from flash into sram1. 6- // release coprocessor reset (rstc_cpmr.cprocen). 8.1.5.4 sub-system 1 start-up time table 8-4 provides the start-up time of su b-system 1 in terms of the number of clock cycles for different cpu speeds. the figures in this table take into account the time to copy 16 kbytes of code from flash into sram1 using the ?memcopy? function from the standard c library and to release core 1 reset signal. the start-up time of the device from power-up is not taken into account. 8.1.5.5 typical execution view figure 8-6 provides the code execution view for both cortex-m4 cores. ahb to apb, ahb to ahb and matrices are not represented in this view. table 8-4. sub-system 1 start-up time core clock (mhz) flash wait state core clock cycles time 21 0 44122 2.1 ms 42 1 45158 1.07 ms 63 2 46203 735 s 85 3 47242 55 s 106 4 48284 455 s 120 5 49329 411 s
45 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 8-6. execution view notes: 1. sram0 can also be used as message buffer exchange. 2. matrices, ahb and apb bridges are not represented. s ram0 core 0, rw data, stack, heap core 0 application core (cortex-m4) core 1 metrology core (cortex-m4f) fl ash core 0 code, ro data core 1 code, ro data core 1 application binary c a che ctrl. (cmcc0) c a che ctrl. (cmcc1) s ram1 s ram2 mpu nvic fpu nvic core 1, rw data, stack, heap core 0 <--> core 1 msg. buffer (1) core 1 code, ro data sub-system 0 sub-system 1 icode / dcode b us icode / dcode b us s -bus s -bus s -bus icode / dcode b us
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46 8.2 external memories the sam4cm external bus interface (ebi) provides the interface to a wide range of external memories and to any parallel peripheral. code execution in memories connect ed to the ebi may benefit from the use of the cache memories. see figure 7-2 and figure 7-3 . the static memory controllers (smc0/1) / external bus interface (ebi) can be used by either the cm4p0 or cm4p1 but only one path is optimized, cm4p0 ? smc0 or cm4p1 ? smc1. the smc0 and smc1 use the same pins on the ebi. only one interface can be used at any time. the selection of the interface is made in the matrix user interface registers (in the system i/o configuration register). the smc0 is used by default.
47 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 9. real-time event management the events generated by peripherals are designed to be directly routed to peripher als managing/using these events without processor intervention. peripherals receiving events contain logic to select the required event. 9.1 embedded characteristics ? timers generate event triggers which are directly ro uted to event managers, such as adc, to start measurement/conversion without processor intervention ? uart, usart, spi, twi, and pio generate event triggers directly connected to peripheral dma controller (pdc) for data transfer without processor intervention ? pmc security event (clock failure detection) can be programmed to switch the mck on reliable main rc internal clock 9.2 real-time event mapping list table 9-1. real-time event mapping list event generator event manager function anti-tamper inputs (tmpx) general-purpose backup register (gpbr) security?immediate gpbr clear (asynchronous) on anti-tamper detection through pins power management controller (pmc) pmc safety?automatic switch to reliable main rc oscillator in case of main cr ystal clock failure tc output 0 adc trigger for measurement. selection in adc. tc output 1 adc trigger for measurement. selection in adc. tc output 2 adc trigger for measurement. selection in adc. tc output 3 adc trigger for measurement. selection in adc. tc output 4 adc trigger for measurement. selection in adc. tc output 5 adc trigger for measurement. selection in adc.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 48 10. system controller the system controller comprises a set of peripherals. it handles key elements of the system, such as power, resets, clocks, time, inte rrupts, watchdog, reinforced safety watchdog, etc. 10.1 system controller and peripheral mapping refer to section 7-2 ?sam4cm16/8 memory mapping of code and sram area? . all the peripherals are in the bit band region and are mapped in the bit band alias region. 10.2 power supply monitoring the sam4cm embeds supply monitor, power-on-reset and brownout detectors for power supplies monitoring allowing to warn and/or reset the chip. 10.2.1 power-on-reset on vddcore the power-on reset monitors vddcore. it is always acti vated and monitors voltage at start-up but also during power-down. if vddcore goes below the threshold voltage, the entire chip (except vddbu domain) is reset. for more information, refer to the ?electrical characteristics? se ction of the product datasheet. 10.2.2 brownout detector on vddcore the brownout detector monito rs vddcore. it is active by default. it can be deactivated by software through the supply controller (supc_mr). if vddcore goes below the threshold volta ge, the reset of the core is asserted. 10.2.3 power-on reset on vddio the power-on reset monitors vddio. it is always activated and monitors voltage at start-up but also during power- down. if vddio goes below the threshold voltage, the ios are reset but the core continues to run. voltage detection is fixed. 10.2.4 supply monitor on vddio the supply monitor on vddio is fully programmable with 16 steps for the threshold (between 1.6v to 3.4v). it provides the user the flexibility to set a voltage level detect ion higher then the power-on -reset on vddio. either a reset or an interrupt can be generated upon detection. it can be activated by software and it is controlled by the supply controller (supc). a sample mode is possible. it divides the supply monitor power consum ption by a factor of up to 2048. the supply monitor is used as ?system alert? in case vddio supply is fa lling. it can be used while the device is in backup mode to wake up the de vice if vddio is falling. 10.2.5 power-on reset and brownout detector on vddbu the power-on reset monitors vddbu. it is active by default and monitors voltage at start-up but also during power-down. it can be deactivated by software through the supply controller (supc_ mr). if vddbu goes below the threshold voltage, the entire chip is reset. 10.2.6 power-on reset on emafe internal vddio the emafe power-on reset monitors vddio. it is always activated and m onitors voltage at start-up but also during power-down. if vddio goes below the threshold voltage, emafe registers are reset and the emafe regulator is shut down. note that this por does not reset the rest of the product. only the emafe related registers are reset.
49 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 10.3 reset controller the reset controller uses the power-on-reset, supply monitor and brownout detector cells. the reset controller returns the source of the last reset to the software. refer to t he description of the field rsttyp in the section ?reset controller (rstc)?. the reset controller controls the internal resets of the system (or independent reset of cm4p1 processor) and the nrst pin input/output. it shapes a reset signal for the exte rnal devices, simplifying to a minimum connection of a push-button on the nrst pin to implement a manual reset. the configuration of the reset controller is saved during backup mode as it is supplied by vddbu. 10.4 supply controller (supc) the supply controller controls the power su pplies of each section of the processor. the supply controller starts up the device by sequentia lly enabling the internal power switches and the voltage regulator, then it generates the proper reset signals to the core power supply. it also sets the system in diff erent low-power modes, wakes it up from a wide range of events.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 50 11. peripherals 11.1 peripheral identifiers table 11-1 defines the peripheral identifiers of the sam4cm. a peripheral identifier is required for the control of the peripheral interrupt with the nested vectored interrupt controller, and for the control of the peripheral clock with the power management controller. the two arm cortex-m4 processors s hare the same interrupt mapping, and t hus, they share all the interrupts of the peripherals. note: some peripherals are on the bus matrix 0/ahb to apb brid ge 0 and other peripherals ar e on the bus matrix 1/ ahb to apb bridge 1. if core 0 needs to access a peripheral on the bus matrix 1/ahb to apb bridge 1, the core 0 application must enable the core 1 system clock (bus and peripherals) and release core 1 system reset (bus and peripherals). peripherals on sub-system 0 or sub-system 1 are menti oned in the instance description table that follows., table 11-1. peripheral identifiers instance id instance name nvic interrupt pmc clock control instance description 0 supc x ? supply controller 1 rstc x ? reset controller 2 rtc x ? real-time clock 3 rtt x ? real-time timer 4 wdt x ? watchdog timer/reinforced watchdog timer 5 pmc x ? power management controller 6 efc0 x ? enhanced embedded flash controller 0 7 efc1 x x enhanced embedded flash controller 1 8 uart0 x x uart 0 (sub-system 0 clock) 9? ? ?r e s e r v e d 10 smc0 ? x static memory controller 0 (sub-system 0 clock) 11 pioa x x parallel i/o contro ller a (sub-system 0 clock) 12 piob x x parallel i/o contro ller b (sub-system 0 clock) 13 ? ? ? reserved 14 usart0 x x usart 0 (sub-system 0 clock) 15 usart1 x x usart 1 (sub-system 0 clock) 16 usart2 x x usart 2 (sub-system 0 clock) 17 usart3 x x usart 3 (sub-system 0 clock) 18 ? ? ? reserved 19 twi0 x x two wire interf ace 0 (sub-system 0 clock) 20 twi1 x x two wire interf ace 1 (sub-system 0 clock) 21 spi0 x x serial peripheral interface 0 (sub-system 0 clock) 22 ? ? ? reserved 23 tc0 x x timer/counter 0 (sub-system 0 clock) 24 tc1 x x timer/counter 1 (sub-system 0 clock) 25 tc2 x x timer/counter 2 (sub-system 0 clock) 26 tc3 x x timer/counter 3 (sub-system 0 clock)
51 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27 tc4 x x timer/counter 4 (sub-system 0 clock) 28 tc5 x x timer/counter 5 (sub-system 0 clock) 29 adc x x analog to digital converter (sub-system 0 clock) 30 arm x ? fpu signals (only on cm4p1 core): fpixc, fpofc, fpufc, fpioc, fpdzc, fpidc, fpixc 31 ipc0 x x interprocessor communication 0 (sub-system 0 clock) 32 slcdc x x segment lcd controller (sub-system 0 clock) 33 trng x x true ra ndom generator (s ub-system 0 clock) 34 icm x x integrity check module (sub-system 0 clock) 35 cpkcc x x classical public key cryptography controller (sub- system 0 clock) 36 aes x x advanced enhanced standard (sub-system 0 clock) 37 pioc x x parallel i/o controller c (sub-system 1 clock) 38 uart1 x x uart 1 (sub-system 1 clock) 39 ipc1 x x interprocessor communication 1 (sub-system 1 clock) 40 ? ? ? reserved 41 pwm x x pulse width modulation (sub-system 1 clock) 42 sram ? x sram1 (i/d code bus of cm4p1), sram2 (system bus of cm4p1) (sub-system 1 clock) 43 smc1 ? x static memory controller 1 (sub-system 1 clock) table 11-1. peripheral id entifiers (continued) instance id instance name nvic interrupt pmc clock control instance description
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 52 11.2 peripheral dma controller (pdc) two peripheral dma controllers (pdc) are available: ? pdc0?dedicated to peripherals on apb0 ? pdc1?dedicated to peripherals on apb1 features of the pdc include: ? data transfer handling between peripherals and memories ? low bus arbitration overhead ? one master clock cycle needed for a tr ansfer from memory to peripheral ? two master clock cycles needed for a transfer from peripheral to memory ? next pointer management to reduce interrupt late ncy requirement note that peripheral dma 0 on matrix 0 cannot access sram1 or sram2. peripheral dma 1 on matrix 1 cannot access sram0. the pdc handles transfer requests from the channel according to the following priorities (low to high priorities): table 11-2. peripheral dma controller (pdc0) instance name channel t/r aes transmit twi0 transmit uart0 transmit usart1 transmit usart0 transmit usart2 transmit usart3 transmit spi0 transmit aes receive twi0 receive uart0 receive usart3 receive usart2 receive usart1 receive usart0 receive adc receive spi0 receive table 11-3. peripheral dma controller (pdc1) instance name channel t/r uart1 transmit uart1 receive
53 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 11.3 apb/ahb bridge the sam4cm embeds two peripheral bridges?one on each matrix, with matrix 0 for cm4p0 and matrix 1 for cm4p1. the peripherals of the bridge corresponding to cm4p0 (apb0) are clocked by mck, and the peripherals of the bridge corresponding to cm4p1 (apb1) are clocked by cpbmck. 11.4 peripheral signal multiplexing on i/o lines the sam4cm can multiplex the i/o lines of the peripheral set. the sam4cm pio controllers control up to 32 lines. each line can be assigned to one of two peripheral functions: a or b. the multiplexing tables that follow define how the i/o lines of th e peripherals a and b are multiplexed on the pio controllers. the column ?comments? has been inse rted in this table for the user?s own comments; it may be used to track how pins are defined in an application. note that some peripheral functions which are output only may be duplic ated within the tables. 11.4.1 pad features in table 11-5 to table 11-7 , the column ?feature? indicates whether the corresponding i/o line has programmable pull-up, pull-down and/or schmitt trigger. table 11-4 provides the key to the abbreviations used. 11.4.2 reset state in table 11-5 to table 11-7 , the column ?reset state? indicates the reset state of the line. ? pio or signal name? indicates whether the pio line resets in i/o mode or in peripheral mode. if ?pio? is mentioned, the pio line is in general-purpose i/o (gpio). if a signal name is mentioned in the ?reset state? column, the pio line is assigned to this function. ? i or o? indicates whether the signal is input or output state. ? pu or pd? indicates whether pull-up , pull-down or nothing is enabled. st? indicates if schmit t trigger is enabled. table 11-4. i/o line features abbreviations abbreviation definition pup(p) programmable pull-up pup(np) non-programmable pull-up pdn(p) programmable pull-down pdn(np) non-programmable pull-down st(p) programmable schmitt trigger st(np) non-programmable schmitt trigger ldrv(p) programmable low drive ldrv(nrp) non-programmable low drive hdrv(p) programmable high drive hdrv(np) non-programmable high drive maxdrv(np) non-programmable maximum drive
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 54 11.4.3 pio controller a multiplexing table 11-5. multiplexing on pio controller a (pioa) i/o line peripheral a peripheral b peripheral c extra function system function feature reset state comments pa0 rts3 pck2 a10 com0 wkup5 - pup(p) / pdn(p) - st(p) - maxdrv(np) pio, i, pu pa1 cts3 ncs1 a9 com1 ? - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pa2 sck3 ncs2 a8 com2 ? pa3 rxd3 ncs3 a7 com3 wkup6 pa4 txd3 ? a6 com4/ad1 ? pa5 spi0_npcs0 ? a5 com5/ad2 ? pa6 spi0_miso ? a4 seg0 ? pa7 spi0_mosi ? a3 seg1 ? pa8 spi0_spck ? a2 seg2 ? - pup(p) / pdn(p) - st(p) - maxdrv(np) pa9 rxd2 ? a1 seg3 wkup2 - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pa10 txd2 ? a0/nbs0 seg4 ? pa11 rxd1 ? a23 seg5 wkup9 pa12 txd1 ? a22/ nandcle seg6/ad0 ? pa13 sck2 tioa0 a21/ nandale seg7 ? pa14 rts2 tiob0 a20 seg8 wkup3 pa15 cts2 tioa4 a19 seg9 ? pa16 sck1 tiob4 a18 seg10 ? pa17 rts1 tclk4 a17 seg11 wkup7 pa18 cts1 tioa5 a16 seg12 ? pa19 rts0 tclk5 a15 seg13 wkup4 pa20 cts0 tiob5 a14 seg14 ? pa21 spi0_npcs1 ? a13 seg15 ? pa22 spi0_npcs2 ? a12 seg16 ? pa23 spi0_npcs3 ? a11 seg17 ? pa24 twd0 ? a10 seg18 wkup1 pa25 twck0 ? a9 seg19 ? pa26 ? ? a8 seg20 ? pa27 ? ? ncs0 seg21 ? pa28 ? ? nrd seg22 ? pa30 pck1 ? a15 ? xout - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) xout pa31 pck0 ? a14 ? xin - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) xin
55 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 11.4.4 pio controller b multiplexing table 11-6. multiplexing on pio controller b (piob) i/o line peripheral a peripheral b peripheral c extra function system function feature reset state comments pb0 twd1 ? ? ? tdi - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) jtag, i pb1 twck1 ? ? rtcout0 tdo/ traceswo - pup(p)/pdn(p) - ldrv(np) jtag, o pb2 ? ? ? ? tms/swdio - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) jtag, i pb3 ? ? ? ? tck/swclk pb4 urxd0 tclk0 a17 ? wkup8 pio, i, pu pb5 utxd0 ? a16 ? ? pb6 ? ? d0 seg24 ? pb7 tioa1 ? d1 seg25 ? pb8 tiob1 ? d2 seg26 ? pb9 tclk1 ? d3 seg27 ? pb10 tioa2 ? d4 seg28 ? pb11 tiob2 ? d5 seg29 ? pb12 tclk2 ? d6 seg30 ? pb13 pck0 ? d7 seg31/ad 3 ? - pup(p) / pdn(p) - st(p) - maxdrv(np) pb14 ? ? nwr0/ nwe seg32 ? - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pb15 ? ? nwr1/ nbs1 seg33 ? pb16 rxd0 ? d8 seg34 wkup10/ tmp1 pio, i, pd tmp1 is only available in sam4cms devices. pb17 txd0 ? d9 seg35 ? pb18 sck0 pck2 d10 seg36 ? pb19 ? ? d11 seg37 ? pb21 ? ? d13 seg39 wkup11
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 56 11.4.5 pio controller c multiplexing table 11-7. multiplexing on pio controller c (pioc) i/o line peripheral a peripheral b peripheral c extra functio n system function feature reset state comments pc0 utxd1 pwm0 ? ? ? - pup(p) - maxdrv(np) pio, i, pu pc1 urxd1 pwm1 ? ? wkup12 - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pc6 pwm0 ? ? ? ? - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pc7 pwm1 ? ? ? ? pc9 pwm3 ? ? ? erase erase, pd
57 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12. arm cortex-m4 processor 12.1 description the cortex-m4 processor is a high performance 32-bit pr ocessor designed for the microcontroller market. it offers significant benefits to developers, including outstanding processing performance combined with fast interrupt handling, enhanced system d ebug with extensive breakpoint and trace capabilities, effici ent processor core, system and memories, ultra-low power consumption wi th integrated sleep modes, and platform security robustness, with integrated memory protection unit (mpu). the cortex-m4 processor is built on a high-performanc e processor core, with a 3-stage pipeline harvard architecture, making it ideal for demanding embedded app lications. the processor delivers exceptional power efficiency through an efficient instruction set and ex tensively optimized design, providing high-end processing hardware including ieee754-compliant si ngle-precision floating-point computat ion, a range of single-cycle and simd multiplication and multiply-with-accumulate capab ilities, saturating arithmetic and dedicated hardware division. to facilitate the design of cost-sensitive devices, the cortex-m4 processor implements tightly-coupled system components that reduce processor ar ea while significantly improving interrupt handling and system debug capabilities. the cortex-m4 processor implements a version of the thumb ? instruction set based on thumb-2 technology, ensuring high code density and reduced progr am memory requirements. the cortex-m4 instruction set provides the exceptional performance expected of a modern 32-bit architecture, with the high code density of 8-bit and 16-bit microcontrollers. the cortex-m4 processor closely in tegrates a configurable nvic, to deliver industry-leading interrupt performance. the nvic includes a non-maskable interrupt (nmi ), and provides up to 256 interrupt priority levels. the tight integration of the processor core and nvic provides fast execution of interrupt service routines (isrs), dramatically reducing the interrupt latency. this is achi eved through the hardware stacking of registers, and the ability to suspend load-multiple and store-multiple operations. interrupt handlers do not require wrapping in assembler code, removing any code overhead from the isrs. a tail-chain optimization also significantly reduces the overhead when switching from one isr to another. to optimize low-power designs, the nvic integrates with the sleep modes, that include a deep sleep function that enables the entire device to be rapidly po wered down while still re taining prog ram state. 12.1.1 system level interface the cortex-m4 processor provides multiple interfaces using amba ? technology to provide high speed, low latency memory accesses. it supports unaligned data accesses and implements atomic bit manipulation that enables faster peripheral controls, system spinlocks and thread-safe boolean data handling. the cortex-m4 processor has a memory protection unit (mpu) that provides fine grain memory control, enabling applications to utilize multiple privilege levels, separating and protecting code, data and stack on a task-by-task basis. such requirements are becoming critical in many embedded applications such as automotive. 12.1.2 integrated configurable debug the cortex-m4 processor implements a co mplete hardware deb ug solution. this provides high system visibility of the processor and memory through either a traditional jtag port or a 2-pin serial wire debug (swd) port that is ideal for microcontrollers and other small package devices. for system trace the processor integrates an instrumentation trace macrocell (itm) alongside data watchpoints and a profiling unit. to enable simple and cost-effective profiling of the system events these generate, a serial wire viewer (swv) can export a stream of software-generated messages, data trace, and profiling information through a single pin.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 58 the flash patch and breakpoint unit (fpb) provides up to eight hardware breakpoint comparators that debuggers can use. the comparators in the fpb also provide remap functions of up to eight words in the program code in the code memory region. this enables applications stored on a non-erasable, rom-based microcontroller to be patched if a small programmable memory, for example flash, is available in the device. during initialization, the application in rom detects, from the programmable memory, whether a patch is required. if a patch is required, the application programs the fpb to remap a number of addresses. when those addresses are accessed, the accesses are redirected to a remap table specified in th e fpb configuration, which means the program in the non- modifiable rom can be patched. 12.2 embedded characteristics ? tight integration of system peripherals reduces area and development costs ? thumb instruction set combines high code density with 32-bit performance ? ieee754-compliant si ngle-precision fpu ? code-patch ability for rom system updates ? power control optimization of system components ? integrated sleep modes fo r low power consumption ? fast code execution permits slower proce ssor clock or increases sleep mode time ? hardware division and fast digital-signal-processing oriented multiply accumulate ? saturating arithmetic for signal processing ? deterministic, high-performance interrup t handling for time-critical applications ? memory protection unit (mpu) for safety-critical applications ? extensive debug and trace capabilities: ? serial wire debug and serial wire trace reduce the number of pins required for debugging, tracing, and code profiling. 12.3 block diagram figure 12-1. typical cortex-m4f implementation nvic debug access port memory protection unit serial wire viewer bus matrix code interface sram and peripheral interface data watchpoints flash patch cortex-m4f processor processor core fpu
59 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.4 cortex-m4 models 12.4.1 programmers model this section describes the cortex-m4 programmers model. in addition to the individual core register descriptions, it contains information about the processor modes and pr ivilege levels for softwa re execution and stacks. 12.4.1.1 processor modes and privilege levels for software execution the processor modes are: ? thread mode used to execute application software. the processor enters the thread mode when it comes out of reset. ? handler mode used to handle exceptions. the processor returns to the thread mode when it has finished exception processing. the privilege levels for software execution are: ? unprivileged the software: ? has limited access to the msr and mrs inst ructions, and cannot use the cps instruction ? cannot access the system timer, nvic, or system control block ? might have a restricted access to memory or peripherals. unprivileged software executes at the unprivileged level. ? privileged the software can use all the instructio ns and has access to all resources. privileged software executes at the privileged level. in thread mode, the control register controls whether the software exec ution is privileged or unprivileged, see ?control register? . in handler mode, software execution is always privileged. only privileged software can write to the control register to change the privilege level for software execution in thread mode. unprivileged software can use the svc instruction to make a supervisor call to transfer control to privileged software. 12.4.1.2 stacks the processor uses a full descending st ack. this means the stack pointer hol ds the address of the last stacked item in memory when the processor pushes a new item onto the stack, it decrement s the stack pointer and then writes the item to the new memory location . the processor implements two stacks, the main stack and the process stack , with a pointer for each held in independent registers, see ?stack pointer? . in thread mode, the control register controls whether the processor uses the main stack or the process stack, see ?control register? . in handler mode, the processor always uses the main stack. the options for processor operations are: note: 1. see ?control register? . table 12-1. summary of processor mode, execution privilege level, and stack use options processor mode used to execute privilege level for software execution stack used thread applications privileged or unprivileged (1) main stack or process stack (1) handler exception handlers always privileged main stack
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 60 12.4.1.3 core registers figure 12-2. processor core registers notes: 1. describes access type during program execution in thread mode and handler mode. debug access can differ. 2. an entry of either means privileged and unprivileged software can access the register. sp (r13) lr (r14) pc (r15) r5 r6 r7 r0 r1 r3 r4 r2 r10 r11 r12 r8 r9 low registers high registers msp ? psp ? psr primask faultmask basepri control general-purpose registers stack pointer link register program counter program status register exception mask registers control register special registers ? banked version of sp table 12-2. core processor registers register name access (1) required privilege (2) reset general-purpose registers r0? r12 read/write either unknown stack pointer msp read/write privileged see description stack pointer psp read /write either unknown link register lr read/write either 0xffffffff program counter pc read/write either see description program status register psr read/write privileged 0x01000000 application program status register apsr read/write either 0x00000000 interrupt program status register ipsr read-only privileged 0x00000000 execution program status register epsr read-only privileged 0x01000000 priority mask register primask read/write privileged 0x00000000 fault mask register faultmask read/write privileged 0x00000000 base priority mask register basepri read/write privileged 0x00000000 control register control read/write privileged 0x00000000
61 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.4.1.4 general-purpose registers r0?r12 are 32-bit general-purpose registers for data operations. 12.4.1.5 stack pointer the stack pointer (sp) is register r13. in thread mode, bit[1] of the control register indicates the stack pointer to use: ? 0 = main stack pointer (msp). this is the reset value. ? 1 = process stack pointer (psp). on reset, the processor loads the msp with the value from address 0x00000000. 12.4.1.6 link register the link register (lr) is register r14. it stores the return information for subroutines, function calls, and exceptions. on reset, the processor loads the lr value 0xffffffff . 12.4.1.7 program counter the program counter (pc) is register r15. it contains the current program address. on reset, the processor loads the pc with the value of the reset vector, which is at address 0x00000004. bit[0] of the value is loaded into the epsr t-bit at reset and must be 1.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 62 12.4.1.8 program status register name: psr access: read/write reset: 0x000000000 the program status register (psr) combines: ? application program status register (apsr) ? interrupt program status register (ipsr) ? execution program status register (epsr). these registers are mutually exclus ive bitfields in the 32-bit psr. the psr accesses these registers individually or as a combi nation of any two or all three registers, using the register name as an argument to the msr or mrs instructions. for example: ? read of all the registers using psr with the mrs instruction ? write to the apsr n, z, c, v and q bits using apsr_nzcvq with the msr instruction. the psr combinations and attributes are: notes: 1. the processor ignores writes to the ipsr bits. 2. reads of the epsr bits return zero, and the processor ignores writes to these bits. see the instruction descriptions ?mrs? and ?msr? for more information about how to access the program status registers. 31 30 29 28 27 26 25 24 nzcvq i c i / i t t 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ici/it ? isr_number 76543210 isr_number name access combination psr read/write (1)(2) apsr, epsr, and ipsr iepsr read-only epsr and ipsr iapsr read/write (1) apsr and ipsr eapsr read/write (2) apsr and epsr
63 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.4.1.9 application program status register name: apsr access: read/write reset: 0x000000000 the apsr contains the current stat e of the conditio n flags from previous instruction executions. ? n: negative flag 0: operation result was positive, zero, greater than, or equal 1: operation result was negative or less than. ? z: zero flag 0: operation result was not zero 1: operation result was zero. ? c: carry or borrow flag carry or borrow flag: 0: add operation did not result in a carry bit or subtract operation resulted in a borrow bit 1: add operation resulted in a carry bit or subt ract operation did not result in a borrow bit. ? v: overflow flag 0: operation did not result in an overflow 1: operation resulted in an overflow. ? q: dsp overflow and saturation flag sticky saturation flag: 0: indicates that saturation has not occurred sinc e reset or since the bit was last cleared to zero 1: indicates when an ssat or usat instruction results in saturation. this bit is cleared to zero by software using an mrs instruction. ? ge[19:16]: greater than or equal flags see ?sel? for more information. 31 30 29 28 27 26 25 24 nzcvq ? 23 22 21 20 19 18 17 16 ? ge[3:0] 15 14 13 12 11 10 9 8 ? 76543210 ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 64 12.4.1.10interrupt program status register name: ipsr access: read/write reset: 0x000000000 the ipsr contains the exception type number of the current interrupt service routine (isr). ? isr_number: number of the current exception 0 = thread mode 1 = reserved 2 = nmi 3 = hard fault 4 = memory management fault 5 = bus fault 6 = usage fault 7?10 = reserved 11 = svcall 12 = reserved for debug 13 = reserved 14 = pendsv 15 = systick 16 = irq0 56 = irq40 see ?exception types? for more information. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? isr_number 76543210 isr_number
65 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.4.1.11 execution progr am status register name: epsr access: read/write reset: 0x000000000 the epsr contains the thumb state bit, and the execution state bits fo r either the if-then (it) instruction, or the interrupt- ible-continuable instruction (ici) field for an interr upted load multiple or st ore multiple instruction. attempts to read the epsr directly th rough application software using the msr inst ruction always return zero. attempts to write the epsr using the msr in struction in the application software are ignore d. fault handlers ca n examine the epsr value in the stacked psr to indicate the operation that is at fault. see ?exception entry and return? . ? ici: interruptible-continuable instruction when an interrupt occurs during the execution of an ldm, stm, push, pop, vldm, vstm, vpush, or vpop instruction, the processor: ? stops the load multiple or store multiple instruction operation temporarily ? stores the next regi ster operand in the multiple operation to epsr bits[15:12]. after servicing the interrupt, the processor: ? returns to the register pointed to by bits[15:12] ? resumes the execution of the multiple load or store instruction. when the epsr holds the ici executio n state, bits[26:25,11:10] are zero. ? it: if-then instruction indicates the execution state bits of the it instruction. the if-then block contains up to four inst ructions following an it instruction. each instruction in the block is conditional. the conditions for the instructions are either all th e same, or some can be the inverse of others. see ?it? for more information. ? t: thumb state the cortex-m4 processor only supports the execution of instructions in thumb state. the following can clear the t bit to 0: ? instructions blx, bx and pop{pc} ? restoration from the stacked xpsr value on an exception return ? bit[0] of the vector value on an exception entry or reset. attempting to execute instructions when the t bit is 0 results in a fault or lockup. see ?lockup? for more information. 31 30 29 28 27 26 25 24 ?i c i / i t t 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ici/it ? 76543210 ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 66 12.4.1.12exception mask registers the exception mask registers disable the handling of exce ptions by the processor. dis able exceptions where they might impact on timing critical tasks. to access the exception mask registers use the msr and mrs instructions, or the cps instruction to change the value of primask or faultmask. see ?mrs? , ?msr? , and ?cps? for more information. 12.4.1.13priority mask register name: primask access: read/write reset: 0x000000000 the primask register prevents the activation of all exceptions with a configurable priority. ?primask 0: no effect 1: prevents the activation of all exceptions with a configurable priority. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? primask
67 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.4.1.14fault mask register name: faultmask access: read/write reset: 0x000000000 the faultmask register prevents the activation of all except ions except fo r non-maskable interrupt (nmi). ? faultmask 0: no effect. 1: prevents the activation of all exceptions except for nmi. the processor clears the faultmask bit to 0 on exit from any exceptio n handler except the nmi handler. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? faultmask
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 68 12.4.1.15base priority mask register name: basepri access: read/write reset: 0x000000000 the basepri register defines the minimum pr iority for exception proces sing. when basepri is set to a nonzero value, it prevents the activation of all exceptions with same or lower priority level as the basepri value. ? basepri priority mask bits: 0x0000: no effect nonzero: defines the base prio rity for exception processing the processor does not process an y exception with a priority value greater than or equal to basepri. this field is similar to the priority fields in the interrupt priority registers. the processo r implements only bits[7:4] of th is field, bits[3:0] read as zero and ignore writes. see ?interrupt priority registers? for more information. remember that higher priority field values corres pond to lower exception priorities. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 basepri
69 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.4.1.16control register name: control access: read/write reset: 0x000000000 the control register controls the stack us ed and the privilege level for software execution when the processor is in thread mode and indicates whether the fpu state is active. ? fpca: floating-point context active indicates whether the floating-point context is currently active: 0: no floating-point context active. 1: floating-point context active. the cortex-m4 uses this bit to determine whether to preserve the floating-poin t state when processing an exception. ? spsel: active stack pointer defines the current stack: 0: msp is the current stack pointer. 1: psp is the current stack pointer. in handler mode, this bit reads as zero and ignores writes . the cortex-m4 updates this bit automatically on exception return. ? npriv: thread mode privilege level defines the thread mode privilege level: 0: privileged. 1: unprivileged. handler mode always uses the msp, so the processor ignores ex plicit writes to the active st ack pointer bit of the control register when in handler mode. the exception entry and retu rn mechanisms update the control register based on the exc_return value. in an os environment, arm recommends that threads running in thread mode use the process stack, and the kernel and exception handlers use the main stack. by default, the thread mode uses the msp. to switch th e stack pointer used in thread mode to the psp, either: ? use the msr instruction to set the active stack pointer bit to 1, see ?msr? , or ? perform an exception return to thread mode with the appropriate exc_return value, see table 12-10 . 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? fpca spsel npriv
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 70 note: when changing the stack pointer, the software must use an i sb instruction immediately after the msr instruction. this ensu res that instructions after the isb execute using the new stack pointer. see ?isb? .
71 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.4.1.17exceptions and interrupts the cortex-m4 processor supports interrupts an d system exceptions. the processor and the nested vectored interrupt controller (nvic) prioritize and handle all exceptions. an exception changes the normal flow of software control. the processor uses the handler mode to handle all exceptions ex cept for reset. see ?exception entry? and ?exception return? for more information. the nvic registers control interrupt handling. see ?nested vectored interrupt controller (nvic)? for more information. 12.4.1.18data types the processor supports the following data types: ? 32-bit words ? 16-bit halfwords ? 8-bit bytes ? the processor manages all data memory accesses as little-endian. instruction memory and private peripheral bus (ppb) accesses are always little-endian. see ?memory regions, types and attributes? for more information. 12.4.1.19 cortex microcontroller software interface standard (cmsis) for a cortex-m4 microc ontroller system, the cortex microcontroller software interface standard (cmsis) defines: ? a common way to: ? access peripheral registers ? define exception vectors ? the names of: ? the registers of the core peripherals ? the core exce ption vectors ? a device-independent interface for rtos kernels, including a debug channel. the cmsis includes address definitions and data structures for the core peripherals in the cortex-m4 processor. the cmsis simplifies the software deve lopment by enabling the reuse of template code and the combination of cmsis-compliant software components from various middleware vendors. software vendors can expand the cmsis to include their peripheral definitions and access functions for those peripherals. this document includes the register names defined by the cmsis, and gives short descriptions of the cmsis functions that address the processo r core and the core peripherals. note: this document uses the register shor t names defined by the cmsis. in a few cases, these differ from the architectural short names that might be used in other documents. the following sections give mo re information about the cmsis: ? section 12.5.3 ?power management programming hints? ? section 12.6.2 ?cmsis functions? ? section 12.8.2.1 ?nvi c programming hints? .
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 72 12.4.2 memory model this section describes the processor memory map, the behavior of memory accesses, and the bit-banding features. the processor has a fixed memory map that provides up to 4 gb of addressable memory. figure 12-3. memory map the regions for sram and peripherals include bit-band r egions. bit-banding provides atomic operations to bit data, see ?bit-banding? . the processor reserves regions of the private peripheral bus (ppb) address range for co re peripheral registers. this memory mapping is generic to arm cortex-m4 products . to get the specific memory mapping of this product, refer to the memories section of the datasheet. 12.4.2.1 memory regions, types and attributes the memory map and the programming of the mpu split the memory map into regions. each region has a defined memory type, and some regions have additional memory at tributes. the memory type and attributes determine the behavior of accesses to the region. memory types ? normal the processor can re-order transactions for efficiency, or perform speculative reads. vendor-specific memory external device external ram peripheral sram code 0xffffffff private peripheral bus 0xe0100000 0xe00fffff 0x9fffffff 0xa0000000 0x5fffffff 0x60000000 0x3fffffff 0x40000000 0x1fffffff 0x20000000 0x00000000 0x40000000 32 mb bit-band alias 0x400fffff 0x42000000 0x43ffffff 1 mb bit-band region 32 mb bit-band alias 0x20000000 0x200fffff 0x22000000 0x23ffffff 1.0 gb 1.0 gb 0.5 gb 0.5 gb 0.5 gb 0x dfffffff 0xe000 0000 1.0 mb 511 mb 1 mb bit-band region
73 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? device the processor preserves transaction order relative to other transactions to device or strongly-ordered memory. ? strongly-ordered the processor preserves transaction order relative to all other transactions. the different ordering requirements for device and str ongly-ordered memory mean that the memory system can buffer a write to device memory, but must not buffer a write to strongly-ordered memory. additional memory attributes ? shareable for a shareable memory region, the memory system pr ovides data synchronization between bus masters in a system with multiple bus masters, for example, a pr ocessor with a dma controller. strongly-ordered memory is always shareable. if multiple bus masters can access a non-shareabl e memory region, the software must ensure data coherency between the bus masters. ? execute never (xn) means the processor prevents instruct ion accesses. a fault exception is generated only on execution of an instruction executed from an xn region. 12.4.2.2 memory system ordering of memory accesses for most memory accesses caused by explicit memo ry access instructions, th e memory system does not guarantee that the order in which the accesses complete matches the program order of the instructions, providing this does not affect the behavior of the instruction sequence. normally, if correct program execution depends on two memory accesses completing in prog ram order, the software must insert a memory barrier instruction between the memory access instructions, see ?software ordering of memory accesses? . however, the memory system does guarantee some ordering of accesses to device and strongly-ordered memory. for two memory access instructions a1 and a2, if a1 occurs before a2 in program order, the ordering of the memory accesses is described below. where: ? means that the memory system does not guarantee the ordering of the accesses. < means that accesses are observed in prog ram order, that is, a1 is always observed before a2. 12.4.2.3 behavior of memory accesses the following table describes the behavior of accesses to each region in the memory map. table 12-3. ordering of the memory accesses caused by two instructions a2 normal access device access strongly- ordered access a1 non- shareable shareable normal access ???? device access, non-shareable ? < ? < device access, shareable ? ? < < strongly-ordered access ? < < <
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 74 note: 1. see ?memory regions, types and attributes? for more information. the code, sram, and external ram regions can hold programs. however, arm recommends that programs always use the code region. this is because the processor has separate buses that enable instruction fetches and data accesses to occur simultaneously. the mpu can override the default memory access behavior described in this section. for more information, see ?memory protection unit (mpu)? . additional memory access constraints for shared memory when a system includes shared memory, some memory regions have additional access constraints, and some regions are subdivided, as table 12-5 shows. notes: 1. see ?memory regions, types and attributes? for more information. instruction prefetch and branch prediction the cortex-m4 processor: ? prefetches instructions ahead of execution ? speculatively prefetches from branch target addresses. table 12-4. memory access behavior address range memory region memory type xn description 0x00000000?0x1fffffff code normal (1) ? executable region for program code. data can also be put here. 0x20000000?0x3fffffff sram normal (1) ? executable region for data. code can also be put here. this region includes bit band and bit band alias areas, see table 12-6 . 0x40000000?0x5fffffff peripheral device (1) xn this region includes bit band and bit band alias areas, see table 12-6 . 0x60000000?0x9fffffff external ram normal (1) ? executable region for data 0xa0000000?0xdfffffff external device device (1) xn external device memory 0xe0000000?0xe00fffff private peripheral bus strongly- ordered (1) xn this region includes the nvic , system timer, and system control block. 0xe0100000?0xffffffff reserved device (1) xn reserved table 12-5. memory region shareability policies address range memory region memory type shareability 0x00000000?0x1fffffff code normal (1) ? 0x20000000?0x3fffffff sram normal (1) ? 0x40000000?0x5fffffff peripheral device (1) ? 0x60000000?0x7fffffff external ram normal (1) ? 0x80000000?0x9fffffff 0xa0000000?0xbfffffff external device device (1) shareable (1) 0xc0000000?0xdfffffff non-shareable (1) 0xe0000000?0xe00fffff private peripheral bus strongly-ordered (1) shareable (1) 0xe0100000?0xffffffff vendor-specific device device (1) ?
75 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.4.2.4 software ordering of memory accesses the order of instructions in the program flow does not always guarantee the order of the corresponding memory transactions. this is because: ? the processor can reorder some memory accesses to im prove efficiency, providing this does not affect the behavior of the instruction sequence. ? the processor has multiple bus interfaces ? memory or devices in the memory map have different wait states ? some memory accesses are buffered or speculative. ?memory system ordering of memory accesses? describes the cases where th e memory system guarantees the order of memory accesses. otherwise, if the order of memory accesses is critical, the software must include memory barrier instructions to force that ordering. the processor provides the following memory barrier instructions: dmb the data memory barrier (dmb) instruction ensures that outstanding memory transactions complete before subsequent memory transactions. see ?dmb? . dsb the data synchronization barrier (dsb) instruction ensures that outstanding memory transactions complete before subsequent instructions execute. see ?dsb? . isb the instruction synchronization barrier (isb) ensures that the effect of all completed memory transactions is recognizable by subsequent instructions. see ?isb? . mpu programming use a dsb followed by an isb instruction or exception return to ensure that the new mpu configuration is used by subsequent instructions. 12.4.2.5 bit-banding a bit-band region maps each word in a bit-band alias region to a single bit in the bit-band region . the bit-band regions occupy the lowest 1 mb of the sram and peripheral memory regions. the memory map has two 32 mb alias regions that map to two 1 mb bit-band regions: ? accesses to the 32 mb sram alia s region map to the 1 mb sram bit-band region, as shown in table 12-6 . ? accesses to the 32 mb peripheral alias region map to the 1 mb peripheral bit-band region, as shown in table 12-7 . table 12-6. sram memory bit-banding regions address range memory region instruction and data accesses 0x20000000?0x200fffff sram bit-band region direct accesses to this memory ran ge behave as sram memory accesses, but this region is also bit-addressable through bit-band alias. 0x22000000?0x23ffffff sram bit-band alias data accesses to this region are remapped to bit-band region. a write operation is performed as read-modify-write. instruction accesses are not remapped. table 12-7. peripheral memory bit-banding regions address range memory region instruction and data accesses 0x40000000?0x400fffff peripheral bit-band alias direct accesses to this memory range behave as peripheral memory accesses, but this region is also bit-addressable through bit-band alias.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 76 notes: 1. a word access to the sram or peripheral bit-band alias r egions map to a single bit in the sram or peripheral bit-band region. 2. bit-band accesses can use byte, halfword, or word transfers. t he bit-band transfer size matches the transfer size of the instruction making the bit-band access. the following formula shows how the alias region maps onto the bit-band region: bit_word_offset = (byte_offset x 32) + (bit_number x 4) bit_word_addr = bit_band_base + bit_word_offset where: ? bit_word_offset is the position of the target bit in the bit-band memory region. ? bit_word_addr is the address of the word in the alias memory region that maps to the targeted bit. ? bit_band_base is the starting address of the alias region. ? byte_offset is the number of the byte in the bit-b and region that contains the targeted bit. ? bit_number is the bit position, 0?7, of the targeted bit. figure 12-4 shows examples of bit-band m apping between the sram bit-band alias region and the sram bit- band region: ? the alias word at 0x23ffffe0 maps to bit[0] of the bit-band byte at 0x200fffff: 0x23ffffe0 = 0x22000000 + (0xfffff*32) + (0*4). ? the alias word at 0x23fffffc maps to bit[7] of the bit-band byte at 0x200fffff: 0x23fffffc = 0x22000000 + (0xfffff*32) + (7*4). ? the alias word at 0x22000000 maps to bit[0] of the bit-band byte at 0x20000000: 0x22000000 = 0x22000000 + (0*32) + (0*4). ? the alias word at 0x2200001c maps to bit[7] of the bit-band byte at 0x20000000: 0x2200001c = 0x22000000+ (0*32) + (7*4). figure 12-4. bit-band mapping 0x42000000?0x43ffffff peripheral bit-band region data accesses to this region are remapped to bit-b and region. a write operation is performed as read-modify-write. instruction accesses are not permitted. table 12-7. peripheral memory bit-banding regions (continued) address range memory region instruction and data accesses 0x23ffffe4 0x22000004 0x23ffffe0 0x23ffffe8 0x23ffffec 0x23fffff0 0x23fffff4 0x23fffff8 0x23fffffc 0x22000000 0x22000014 0x22000018 0x2200001c 0x22000008 0x22000010 0x2200000c 32 mb alias region 0 7 0 0 7 0x20000000 0x20000001 0x20000002 0x20000003 6 5 4 3 2 1 0 7 6 5 4 3 2 1 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0x200ffffc 0x200ffffd 0x200ffffe 0x200fffff 1 mb sram bit-band region
77 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 directly accessing an alias region writing to a word in the alias region updates a single bit in the bit-band region. bit[0] of the value written to a word in the alias region determines the value written to the targeted bit in the bit- band region. writing a value with bit[0] set to 1 writes a 1 to the bit-band bit, and writing a value with bit[0] set to 0 writes a 0 to the bit-band bit. bits[31:1] of the alias word have no effect on the bit-band bit. writing 0x01 has the same effect as writing 0xff . writing 0x00 has the same effect as writing 0x0e . reading a word in the alias region: ? 0x00000000 indicates that the targeted bit in the bit-band region is set to 0 ? 0x00000001 indicates that the targeted bit in the bit-band region is set to 1 directly accessing a bit-band region ?behavior of memory accesses? describes the behavior of direct byte, halfword, or word accesses to the bit-band regions. 12.4.2.6 memory endianness the processor views memory as a linea r collection of bytes numbered in ascending order from zero. for example, bytes 0?3 hold the first stored word, and bytes 4?7 hold the second stored word. ?little-endian format? describes how words of data are stored in memory. little-endian format in little-endian format, the processor stores the least signifi cant byte of a word at the lowest-numbered byte, and the most significant byte at the highest-numbered byte. for example: figure 12-5. little-endian format 12.4.2.7 synchronization primitives the cortex-m4 instruction set includes pairs of synchronization primitives . these provide a non-blocking mechanism that a thread or process can use to obtain exclusive access to a memory location. the software can use them to perform a guaranteed re ad-modify-write memory update seque nce, or for a semaphore mechanism. a pair of synchronization primitives comprises: a load-exclusive instruction , used to read the value of a memory loca tion, requesting excl usive access to that location. a store-exclusive instruction , used to attempt to write to the same me mory location, returning a status bit to a register. if this bit is: ? 0: it indicates that the thread or process gained e xclusive access to the memory, and the write succeeds, ? 1: it indicates that the thread or process did not gain exclusive access to the memory, and no write is performed. memory register address a a+1 lsbyte msbyte a+2 a+3 07 b0 b1 b3 b2 31 24 23 16 15 8 7 0 b0 b1 b2 b3
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 78 the pairs of load-exclusive and st ore-exclusive instructions are: ? the word instructions ldrex and strex ? the halfword in structions ldrexh and strexh ? the byte instructio ns ldrexb and strexb. the software must use a load-exclusive instruction with the corresponding store-exclusive instruction. to perform an exclusive read-modify-write of a memory location, the software must: 1. use a load-exclusive instruction to read the value of the location. 2. update the value, as required. 3. use a store-exclusive instruction to attempt to write the new value back to the memory location 4. test the returned status bit. if this bit is: 0: the read-modify-write completed successfully. 1: no write was performed. this in dicates that the value returned at step 1 might be out of date. the software must retry the read-modify-write sequence. the software can use the synchronization primitives to implement a semaphore as follows: 1. use a load-exclusive instruction to read from the semaphore address to check whether the semaphore is free. 2. if the semaphore is free, use a store-exclusive in struction to write the claim value to the semaphore address. 3. if the returned status bit from step 2 indicates th at the store-exclusive instruction succeeded then the software has claimed the semaphore. however, if th e store-exclusive instructio n failed, another process might have claimed the semaphore after the software performed the first step. the cortex-m4 includes an exclusive ac cess monitor, that tags the fact that the processor has executed a load- exclusive instruction. if the processor is part of a multiprocessor system, the system also globally tags the memory locations addressed by exclusiv e accesses by each processor. the processor removes its exclusive access tag if: ? it executes a clrex instruction ? it executes a store-exclusive instruction, regardless of whether the write succeeds. ? an exception occurs. this means t hat the processor can resolve semaphore conflicts between different threads. in a multiprocessor implementation: ? executing a clrex instruction removes only the local exclusive access tag for the processor ? executing a store-exclusive instruction, or an exceptio n, removes the local exclus ive access tags, and all global exclusive access tags for the processor. for more information about the synchr onization primitive instructions, see ?ldrex and strex? and ?clrex? . 12.4.2.8 programming hints for th e synchronization primitives iso/iec c cannot directly generate th e exclusive access instructions. cmsi s provides intrinsic functions for generation of these instructions: table 12-8. cmsis functions fo r exclusive access instructions instruction cmsis function ldrex uint32_t __ldrexw (uint32_t *addr) ldrexh uint16_t __ldrexh (uint16_t *addr) ldrexb uint8_t __ldr exb (uint8_t *addr)
79 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the actual exclusive access instruct ion generated depends on the data type of the pointer passed to the intrinsic function. for example, the following c code g enerates the requir ed ldrexb operation: __ldrex((volatile char *) 0xff); 12.4.3 exception model this section describes the exception model. 12.4.3.1 exception states each exception is in one of the following states: inactive the exception is not active and not pending. pending the exception is waiting to be serviced by the processor. an interrupt request from a peripheral or from software can change the state of the corresponding interrupt to pending. active an exception is being serviced by the processor but has not completed. an exception handler can interrupt the execution of anothe r exception handler. in this case, both exceptions are in the active state. active and pending the exception is being serviced by the processor and there is a pending exception from the same source. 12.4.3.2 exception types the exception types are: reset reset is invoked on power up or a warm reset. the exception model treats reset as a special form of exception. when reset is asserted, the operation of the processor stops, pote ntially at any point in an instruction. when reset is deasserted, execution restarts from the address provided by the reset entry in the vector table. execution restarts as privileged execution in thread mode. non maskable interrupt (nmi) a non maskable interrupt (nmi) can be signalled by a peripher al or triggered by software. this is the highest priority exception other than reset. it is perma nently enabled and has a fixed priority of -2. nmis cannot be: ? masked or prevented from activation by any other exception. ? preempted by any exception other than reset. hard fault strex uint32_t __strexw (uint32_t value, uint32_t *addr) strexh uint32_t __strexh (uint16_t value, uint16_t *addr) strexb uint32_t __strexb (uin t8_t value, uint8_t *addr) clrex void __clrex (void) table 12-8. cmsis functions for excl usive access instructions (continued) instruction cmsis function
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 80 a hard fault is an exception that occurs because of an er ror during exception processing, or because an exception cannot be managed by any other excepti on mechanism. hard faults have a fixed priority of -1, meaning they have higher priority than any exception with configurable priority. memory management fault (memmanage) a memory management fault is an exception that occurs because of a memory protection related fault. the mpu or the fixed memory protection constrai nts determines this fault, for both in struction and data memory transactions. this fault is used to abort instruction accesses to execute never (xn) memory regions, even if the mpu is disabled. bus fault a bus fault is an exception that occurs because of a memory related fault for an instruction or data memory transaction. this might be from an error detected on a bus in the memory system. usage fault a usage fault is an exception that occu rs because of a fault related to an instruction execution. this includes: ? an undefined instruction ? an illegal unaligned access ? an invalid state on instruction execution ? an error on exception return. the following can cause a usage fault when the core is configured to report them: ? an unaligned address on word and halfword memory access ? a division by zero. svcall a supervisor call (svc) is an exception that is triggered by the svc instruction. in an os environment, applications can use svc instructions to access os kernel functions and device drivers. pendsv pendsv is an interrupt-driven request for system-level service. in an os environment, use pendsv for context switching when no other exception is active. systick a systick exception is an exception the system timer ge nerates when it reaches zero. software can also generate a systick exception. in an os environment, the pr ocessor can use this exception as system tick. interrupt (irq) a interrupt, or irq, is an exception signalled by a peripher al, or generated by a software request. all interrupts are asynchronous to instruction execution. in the system, peripherals use interrupts to communicate with the processor. table 12-9. properties of the different exception types exception number (1) irq number (1) exception type priority vector address or offset (2) activation 1 ? reset -3, the highest 0x00000004 asynchronous 2 -14 nmi -2 0x00000008 asynchronous 3 -13 hard fault -1 0x0000000c ? 4 -12 memory management fault configurable (3) 0x00000010 synchronous 5 -11 bus fault configurable (3) 0x00000014 synchronous when precise, asynchronous when imprecise
81 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 notes: 1. to simplify the software layer, the cmsis only uses irq numbers and therefore uses negativ e values for exceptions other than interrupts. the ipsr returns the exception number, see ?interrupt program status register? . 2. see ?vector table? for more information 3. see ?system handler priority registers? 4. see ?interrupt priori ty registers? 5. increasing in steps of 4. for an asynchronous exception, other than reset, the processor can execute another instruction between when the exception is triggered and when the processor enters the exception handler. privileged software can disable the exceptions that table 12-9 shows as having configurable priority, see: ? ?system handler control and state register? ? ?interrupt clear-enable registers? . for more information about hard faults, memory management faults, bus faults, and usage faults, see ?fault handling? . 12.4.3.3 exception handlers the processor handles exceptions using: ? interrupt service routines (isrs) interrupts irq0 to irq40 are the exceptions handled by isrs. ? fault handlers hard fault, memory management fault, usage fault, bus fault are fault exceptions handled by the fault handlers. ? system handlers nmi, pendsv, svcall systick, and the fault exceptio ns are all system exceptions that are handled by system handlers. 12.4.3.4 vector table the vector table contains the reset value of the stac k pointer, and the start addresses, also called exception vectors, for all exception handlers. figure 12-6 shows the order of the exception vectors in the ve ctor table. the least-significant bit of each vector must be 1, indicating that the exception handler is thumb code. 6 -10 usage fault configurable (3) 0x00000018 synchronous 7?10 ? ? ? reserved ? 11 -5 svcall configurable (3) 0x0000002c synchronous 12?13 ? ? ? reserved ? 14 -2 pendsv configurable (3) 0x00000038 asynchronous 15 -1 systick configurable (3) 0x0000003c asynchronous 16 and above 0 and above i nterrupt (irq) configurable (4) 0x00000040 and above (5) asynchronous table 12-9. properties of the different exception types (continued) exception number (1) irq number (1) exception type priority vector address or offset (2) activation
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 82 figure 12-6. vector table on system reset, the vector table is fixed at address 0x00000000. privileged software can write to the scb_vtor to relocate the vector table start address to a different memory location, in the range 0x00000080 to 0x3fffff80, see ?vector table offset register? . 12.4.3.5 exception priorities as table 12-9 shows, all exceptions have an associated priority, with: ? a lower priority value indicating a higher priority ? configurable priorities for all except ions except reset, hard fault and nmi. if the software does not configure any priorities, then all exceptions with a configurable priority have a priority of 0. for information about configuring exception priorities see ?system handler prio rity registers? , and ?interrupt priority registers? . note: configurable priority values are in the range 0?15. this means that the reset, hard f ault, and nmi exceptions, with fixed negative priority values, always have higher priority than any other exception. for example, assigning a higher priority value to irq[0] and a lower priority value to irq[1] means that irq[1] has higher priority than irq[0]. if both irq[1] and irq[ 0] are asserted, irq[1] is processed before irq[0]. if multiple pending exceptions have the same priority, the pending exception with the lowest exception number takes precedence. for example, if both irq[0] and irq[ 1] are pending and have the same priority, then irq[0] is processed before irq[1]. initial sp value reset hard fault nmi memory management fault usage fault bus fault 0x0000 0x0004 0x0008 0x000c 0x0010 0x0014 0x0018 reserved svcall pendsv reserved for debug systick irq0 reserved 0x002c 0x0038 0x003c 0x0040 offset exception number 2 3 4 5 6 11 12 14 15 16 18 13 7 10 1 vector . . . 8 9 irq1 irq2 0x0044 irq239 17 0x0048 0x004c 255 . . . . . . 0x03fc irq number -14 -13 -12 -11 -10 -5 -2 -1 0 2 1 239
83 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 when the processor is executing an exception handler, th e exception handler is preempted if a higher priority exception occurs. if an exception occurs with the same prio rity as the exception being handled, the handler is not preempted, irrespective of the exception number. however, the status of the new interrupt changes to pending. 12.4.3.6 interrupt priority grouping to increase priority control in systems with interrupts, the nvic supports priority grouping. this divides each interrupt priority register entry into two fields: ? an upper field that defines the group priority ? a lower field that defines a subpriority within the group. only the group priority determines preemption of interrupt exceptions. when the processor is executing an interrupt exception handler, another interrupt with the same group priority as the interrupt being handled does not preempt the handler. if multiple pending interrupts have the same group priority , the subpriority field determines the order in which they are processed. if multiple pending interrupts have the same group priority and subpriority, the interrupt with the lowest irq number is processed first. for information about splitting the interrupt priority fields into group priority and subpriority, see ?application interrupt and reset control register? . 12.4.3.7 exception entry and return descriptions of exception handling use the following terms: preemption when the processor is executing an exception handler, an exception can preempt the exception handler if its priority is higher than the priority of the exception being handled. see ?interrupt priority grouping? for more information about preemption by an interrupt. when one exception preempts another, the exceptions are called nested exceptions. see ?exception entry? more information. return this occurs when the exceptio n handler is completed, and: ? there is no pending exception with sufficient priority to be serviced ? the completed exception handler was not handling a late-arriving exception. the processor pops the stack and restor es the processor state to the stat e it had before the interrupt occurred. see ?exception return? for more information. tail-chaining this mechanism speeds up exception servicing. on completion of an exception handler, if there is a pending exception that meets the requirement s for exception entry, the stack pop is skipped and control transfers to the new exception handler. late-arriving this mechanism speeds up preemption. if a higher priori ty exception occurs during state saving for a previous exception, the processor switches to handle the higher priority exception and initiates the vector fetch for that exception. state saving is not affected by late arrival because the state saved is the same for both exceptions. therefore the state saving continues uninterrupted. the processor can accept a late arriving exception until the first instruction of the exception handler of the original exception enters the execute stage of the processor. on return from the exception handler of the late-arriv ing exception, the normal tail-chaining rules apply. exception entry
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 84 an exception entry occurs when there is a pending excepti on with sufficient priority and either the processor is in thread mode, or the new exception is of a higher priori ty than the exception being handled, in which case the new exception preempts the original exception. when one exception preempts anot her, the exceptions are nested. sufficient priority means that the exception has more pr iority than any limits set by the mask registers, see ?exception mask registers? . an exception with less priority t han this is pending but is not handled by the processor. when the processor takes an exception, unless the except ion is a tail-chained or a late-arriving exception, the processor pushes information onto the current stack. this operation is referred as stacking and the structure of eight data words is referred to as stack frame . when using floating-point routines, the cortex-m4 processor automatically stacks the architected floating-point state on exception entry. figure 12-7 on page 84 shows the cortex-m4 stack fr ame layout when floating-point state is preserved on the stack as the re sult of an interrup t or an exception. note: where stack space for floating-point state is not alloca ted, the stack frame is the same as that of armv7-m implementations without an fpu. figure 12-7 on page 84 shows this stack frame also. figure 12-7. exception stack frame immediately after stacking, the stack pointer indicates the lowest address in the stack frame. the alignment of the stack frame is controlled via the stkalign bit of the configuration c ontrol register (ccr). the stack frame includes the return address. this is the address of the next instruction in the interrupted program. this value is restored to the pc at exception return so that the interrupted program resumes. pre-irq top of stack xpsr pc lr r12 r3 r2 r1 r0 {aligner} irq top of stack decreasing memory address xpsr pc lr r12 r3 r2 r1 r0 s7 s6 s5 s4 s3 s2 s1 s0 s9 s8 fpscr s15 s14 s13 s12 s11 s10 {aligner} irq top of stack ... exception frame with floating-point storage exception frame without floating-point storage pre-irq top of stack ...
85 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 in parallel to the stacking operation, the processor performs a vector fetch that reads the exception handler start address from the vector table. when stacking is complete , the processor starts execut ing the exception handler. at the same time, the processor writes an exc_return value to the lr. this indicates which stack pointer corresponds to the stack frame and what operation mo de the processor was in before the entry occurred. if no higher priority exception occurs during the exce ption entry, the processor starts executing the exception handler and automatically changes the status of the corresponding pending interrupt to active. if another higher priority exception occurs during the exce ption entry, the processor starts executing the exception handler for this exception and does not c hange the pending status of the earlier ex ception. this is the late arrival case. exception return an exception return occurs when the processor is in h andler mode and executes one of the following instructions to load the exc_return value into the pc: ? an ldm or pop instruction that loads the pc ? an ldr instruction with the pc as the destination. ? a bx instruction using any register. exc_return is the value loaded into the lr on except ion entry. the exception mechanism relies on this value to detect when the processor has completed an exception handler. the lowest five bits of this value provide information on the return stack and processor mode. table 12-10 shows the exc_return values with a description of the exc eption return behavior. all exc_return values have bits[31:5] se t to one. when this value is loade d into the pc, it indicates to the processor that the exception is complete, and the proce ssor initiates the appropriate exception return sequence. 12.4.3.8 fault handling faults are a subset of the exceptions, see ?exception model? . the following generate a fault: ? a bus error on: ? an instruction fetch or vector table load ? a data access ? an internally-detected error such as an undefined instruction ? an attempt to execute an instructi on from a memory region marked as non-executable (xn) . ? a privilege violation or an attempt to acce ss an unmanaged region causing an mpu fault. fault types table 12-10. exception return behavior exc_return[31:0] description 0xfffffff1 return to handler mode, exception re turn uses non-floating-point state from the msp and execution uses msp after return. 0xfffffff9 return to thread mode, exception return uses state from msp and execution uses msp after return. 0xfffffffd return to thread mode, exception return uses state from the psp and execution uses psp after return. 0xffffffe1 return to handler mode, exception return uses floating-point-state from msp and execution uses msp after return. 0xffffffe9 return to thread mode, exception return uses floating-point state from msp and execution uses msp after return. 0xffffffed return to thread mode, exception return uses floating-point state from psp and execution uses psp after return.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 86 table 12-11 shows the types of fault, the handler used for the fault, the corresponding fault status register, and the register bit that indicates that the fault has occurred. see ?configurable fault status register? for more information about the fault st atus registers. notes: 1. occurs on an access to an xn region even if the processor does not include an mpu or the mpu is disabled. 2. attempt to use an instruction set other than the thumb instruct ion set, or return to a non l oad/store-multiple instruction wi th ici continuation. 3. only present in a cortex-m4f device fault escalation and hard faults all faults exceptions except for hard faul t have configurable exception priority, see ?system handler priority registers? . the software can disable the execution of the handlers for these faults, see ?system handler control and state register? . usually, the exception priority, together with the values of the exception mask registers, determines whether the processor enters the fault handler, and whether a fault handler can preempt another fault handler, as described in ?exception model? . in some situations, a fault with configurable priority is treated as a hard fault. this is called priority escalation , and the fault is described as escalated to hard fault . escalation to hard fault occurs when: ? a fault handler causes the same kind of fault as the one it is servicing. this esca lation to hard fault occurs because a fault handler cannot preempt itself; it must have the same prio rity as the current priority level. table 12-11. faults fault handler bit name fault status register bus error on a vector read hard fault vecttbl ?hard fault status register? fault escalated to a hard fault forced mpu or default memory map mismatch: memory management fault ?? on instruction access iaccviol (1) ?mmfsr: memory management fault status subregister? on data access daccviol (2) during exception stacking mstkerr during exception unstacking munstkerr during lazy floating-point state preservation mlsperr (3) bus error: bus fault ?? during exception stacking stkerr ?bfsr: bus fault status subregister? during exception unstacking unstkerr during instruction prefetch ibuserr during lazy floating-point state preservation lsperr (3) precise data bus error preciserr imprecise data bus error impreciserr attempt to access a coprocessor usage fault nocp ?ufsr: usage fault status subregister? undefined instruction undefinstr attempt to enter an invalid instruction set state invstate invalid exc_return value invpc illegal unaligned load or store unaligned divide by 0 divbyzero
87 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? a fault handler causes a fault with the same or lower priori ty as the fault it is servicing. this is because the handler for the new fault cannot preempt the currently executing fault handler. ? an exception handler causes a fault for which the prio rity is the same as or lower than the currently executing exception. ? a fault occurs and the handler for that fault is not enabled. if a bus fault occurs during a stack push when entering a bus fault handler, the bus faul t does not escalate to a hard fault. this means that if a corrupted stack causes a fault, the fault handler executes even though the stack push for the handler failed. the fault handler operates but the stack contents are corrupted. note: only reset and nmi can preempt the fixed priority hard fault. a hard fault can preempt any exception other than reset, nmi, or another hard fault. fault status registers and fault address registers the fault status registers indicate the cause of a faul t. for bus faults and memory management faults, the fault address register indicates the address accessed by the operation that caused the fault, as shown in table 12-12 . lockup the processor enters a lockup state if a hard fault occurs when executing the nmi or hard fault handlers. when the processor is in lockup state, it do es not execute any instructions. the processor remains in lockup state until either: ? it is reset ? an nmi occurs ? it is halted by a debugger. note: if the lockup state occurs from the nmi handler, a su bsequent nmi does not cause the processor to leave the lockup state. table 12-12. fault status an d fault address registers handler status register name address register name register description hard fault scb_hfsr ? ?hard fault status register? memory management fault mmfsr scb_mmfar ?mmfsr: memory management fault status subregister? ?memmanage fault address register? bus fault bfsr scb_bfar ?bfsr: bus fault status subregister? ?bus fault address register? usage fault ufsr ? ?ufsr: usage fault status subregister?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 88 12.5 power management the cortex-m4 processor sleep modes reduce the power consumption: ? sleep mode stops the processor clock ? deep sleep mode stops the system clock and switches off the pll and flash memory. the sleepdeep bit of the scr select s which sleep mo de is used; see ?system control register? . this section describes the mechanisms for entering sleep mode, and the conditions for waking up from sleep mode. 12.5.1 entering sleep mode this section describes the mechanisms software can use to put the processor into sleep mode. the system can generate spurious wakeup events, for example a debug operation wakes up the processor. therefore, the software must be able to put the processor back into sleep mode after such an event. a program might have an idle loop to put the processor back to sleep mode. 12.5.1.1 wait for interrupt the wait for interrupt instruction, wfi, causes immediate entry to sleep mode. when the processor executes a wfi instruction it stops executing instructions and enters sleep mode. see ?wfi? for more information. 12.5.1.2 wait for event the wait for event instruction, wfe, causes entry to sleep mode conditional on the value of an one-bit event register. when the processor executes a wf e instruction, it checks this register: ? if the register is 0, the processor stops executing instructions and enters sleep mode ? if the register is 1, th e processor clears the register to 0 and continues executing instructions without entering sleep mode. see ?wfe? for more information. 12.5.1.3 sleep-on-exit if the sleeponexit bit of the scr is set to 1 when t he processor completes the execution of an exception handler, it returns to thread mode and immediately enters sleep mode. use this mechanism in applications that only require the processor to run when an exception occurs. 12.5.2 wakeup from sleep mode the conditions for the processor to wake up depend on the mechanism that cause it to enter sleep mode. 12.5.2.1 wakeup from wf i or sleep-on-exit normally, the processor wakes up only when it detects an ex ception with sufficient priority to cause exception entry. some embedded systems might have to execute system rest ore tasks after the processor wakes up, and before it executes an interrupt handler. to achieve this, set th e primask bit to 1 and the faultmask bit to 0. if an interrupt arrives that is enabled and has a higher priority than the current exception priority, the processor wakes up but does not execute the interrupt handler until the processor sets primask to zero. for more information about primask and faultmask, see ?exception mask registers? . 12.5.2.2 wakeup from wfe the processor wakes up if: ? it detects an exception with sufficient priority to cause an exception entry ? it detects an external event signal. see ?external event input? ? in a multiprocessor sys tem, another processo r in the system executes an sev instruction.
89 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 in addition, if the sevonpend bit in th e scr is set to 1, any new pending in terrupt triggers an event and wakes up the processor, even if the interrupt is disabled or has insufficient priority to caus e an exception entry. for more information about the scr, see ?system control register? . 12.5.2.3 external event input the processor provides an external event input signal. pe ripherals can drive this signal, either to wake the processor from wfe, or to set the internal wfe event register to 1 to indicate that the processor must not enter sleep mode on a later wfe instruction. see ?wait for event? for more information. 12.5.3 power management programming hints iso/iec c cannot directly generate the wfi and wfe inst ructions. the cmsis provides the following functions for these instructions: void __wfe(void) // wait for event void __wfi(void) // wait for interrupt
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 90 12.6 cortex-m4 instruction set 12.6.1 instruct ion set summary the processor implements a version of the thumb instruction set. table 12-13 lists the supported instructions. ? angle brackets, <>, enclose alternative forms of the operand ? braces, {}, enclose optional operands ? the operands column is not exhaustive ? op2 is a flexible second operand that can be either a register or a constant ? most instructions can use an optional condition code suffix. for more information on the instructions and operands, see the instruction descriptions. table 12-13. cortex-m4 instructions mnemonic operands description flags adc, adcs {rd,} rn, op2 add with carry n,z,c,v add, adds {rd,} rn, op2 add n,z,c,v add, addw {rd,} rn, #imm12 add n,z,c,v adr rd, label load pc-relative address ? and, ands {rd,} rn, op2 logical and n,z,c asr, asrs rd, rm, arithmetic shift right n,z,c b label branch ? bfc rd, #lsb, #width bit field clear ? bfi rd, rn, #lsb, #width bit field insert ? bic, bics {rd,} rn, op2 bit clear n,z,c bkpt #imm breakpoint ? bl label branch with link ? blx rm branch indirect with link ? bx rm branch indirect ? cbnz rn, label compare and branch if non zero ? cbz rn, label compare and branch if zero ? clrex ? clear exclusive ? clz rd, rm count leading zeros ? cmn rn, op2 compare negative n,z,c,v cmp rn, op2 compare n,z,c,v cpsid i change processor state, disable interrupts ? cpsie i change processor state, enable interrupts ? dmb ? data memory barrier ? dsb ? data synchronization barrier ? eor, eors {rd,} rn, op2 exclusive or n,z,c isb ? instruction synchronization barrier ? it ? if-then condition block ? ldm rn{!}, reglist load multiple registers, increment after ?
91 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ldmdb, ldmea rn{!}, reglist load mult iple registers, decrement before ? ldmfd, ldmia rn{!}, reglist load mult iple registers, increment after ? ldr rt, [rn, #offset] load register with word ? ldrb, ldrbt rt, [rn, #offset] load register with byte ? ldrd rt, rt2, [rn, #offset] load register with two bytes ? ldrex rt, [rn, #offset] load register exclusive ? ldrexb rt, [rn] load register exclusive with byte ? ldrexh rt, [rn] load register exclusive with halfword ? ldrh, ldrht rt, [rn, #offset] l oad register with halfword ? ldrsb, drsbt rt, [rn, #offset] load register with signed byte ? ldrsh, ldrsht rt, [rn, #offset] load register with signed halfword ? ldrt rt, [rn, #offset] load register with word ? lsl, lsls rd, rm, logical shift left n,z,c lsr, lsrs rd, rm, logical shift right n,z,c mla rd, rn, rm, ra multiply with accumulate, 32-bit result ? mls rd, rn, rm, ra multiply and subtract, 32-bit result ? mov, movs rd, op2 move n,z,c movt rd, #imm16 move top ? movw, mov rd, #imm16 move 16-bit constant n,z,c mrs rd, spec_reg move from special register to general register ? msr spec_reg, rm move from general r egister to special register n,z,c,v mul, muls {rd,} rn, rm multiply, 32-bit result n,z mvn, mvns rd, op2 move not n,z,c nop ? no operation ? orn, orns {rd,} rn, op2 logical or not n,z,c orr, orrs {rd,} rn, op2 logical or n,z,c pkhtb, pkhbt {rd,} rn, rm, op2 pack halfword ? pop reglist pop registers from stack ? push reglist push registers onto stack ? qadd {rd,} rn, rm saturating double and add q qadd16 {rd,} rn, rm saturating add 16 ? qadd8 {rd,} rn, rm saturating add 8 ? qasx {rd,} rn, rm saturating add and subtract with exchange ? qdadd {rd,} rn, rm saturating add q qdsub {rd,} rn, rm saturating double and subtract q qsax {rd,} rn, rm saturating s ubtract and add with exchange ? qsub {rd,} rn, rm saturating subtract q table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 92 qsub16 {rd,} rn, rm saturating subtract 16 ? qsub8 {rd,} rn, rm saturating subtract 8 ? rbit rd, rn reverse bits ? rev rd, rn reverse byte order in a word ? rev16 rd, rn reverse byte order in each halfword ? revsh rd, rn reverse byte order in bottom halfword and sign extend ? ror, rors rd, rm, rotate right n,z,c rrx, rrxs rd, rm rotate right with extend n,z,c rsb, rsbs {rd,} rn, op2 reverse subtract n,z,c,v sadd16 {rd,} rn, rm signed add 16 ge sadd8 {rd,} rn, rm signed add 8 and subtract with exchange ge sasx {rd,} rn, rm signed add ge sbc, sbcs {rd,} rn, op2 subtract with carry n,z,c,v sbfx rd, rn, #lsb, #width signed bit field extract ? sdiv {rd,} rn, rm signed divide ? sel {rd,} rn, rm select bytes ? sev ? send event ? shadd16 {rd,} rn, rm signed halving add 16 ? shadd8 {rd,} rn, rm signed halving add 8 ? shasx {rd,} rn, rm signed halving add and subtract with exchange ? shsax {rd,} rn, rm signed halving subtract and add with exchange ? shsub16 {rd,} rn, rm signed halving subtract 16 ? shsub8 {rd,} rn, rm signed halving subtract 8 ? smlabb, smlabt, smlatb, smlatt rd, rn, rm, ra signed multiply accumulate long (halfwords) q smlad, smladx rd, rn, rm, ra signed multiply accumulate dual q smlal rdlo, rdhi, rn, rm signed multiply with accumulate (32 32 + 64), 64-bit result ? smlalbb, smlalbt, smlaltb, smlaltt rdlo, rdhi, rn, rm signed multiply accumulate long, halfwords ? smlald, smlaldx rdlo, rdhi, rn, rm signed multiply accumulate long dual ? smlawb, smlawt rd, rn, rm, ra signed multiply accumulate, word by halfword q smlsd rd, rn, rm, ra signed multiply subtract dual q smlsld rdlo, rdhi, rn, rm signed multiply subtract long dual smmla rd, rn, rm, ra signed most significant word multiply accumulate ? smmls, smmlr rd, rn, rm, ra signed most significant word multiply subtract ? smmul, smmulr {rd,} rn, rm signed most significant word multiply ? smuad {rd,} rn, rm signed dual multiply add q table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
93 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 smulbb, smulbt smultb, smultt {rd,} rn, rm signed multiply (halfwords) ? smull rdlo, rdhi, rn, rm signed multiply (32 32), 64-bit result ? smulwb, smulwt {rd,} rn, rm signed multiply word by halfword ? smusd, smusdx {rd,} rn, rm signed dual multiply subtract ? ssat rd, #n, rm {,shift #s} signed saturate q ssat16 rd, #n, rm signed saturate 16 q ssax {rd,} rn, rm signed subtract and add with exchange ge ssub16 {rd,} rn, rm signed subtract 16 ? ssub8 {rd,} rn, rm signed subtract 8 ? stm rn{!}, reglist store multiple registers, increment after ? stmdb, stmea rn{!}, reglist store multiple registers, decrement before ? stmfd, stmia rn{!}, reglist store mu ltiple registers, increment after ? str rt, [rn, #offset] store register word ? strb, strbt rt, [rn, #offset] store register byte ? strd rt, rt2, [rn, #offset] store register two words ? strex rd, rt, [rn, #offset] store register exclusive ? strexb rd, rt, [rn] store register exclusive byte ? strexh rd, rt, [rn] store register exclusive halfword ? strh, strht rt, [rn, #offset] store register halfword ? strt rt, [rn, #offset] store register word ? sub, subs {rd,} rn, op2 subtract n,z,c,v sub, subw {rd,} rn, #imm12 subtract n,z,c,v svc #imm supervisor call ? sxtab {rd,} rn, rm,{,ror #} extend 8 bits to 32 and add ? sxtab16 {rd,} rn, rm,{,ror #} dual extend 8 bits to 16 and add ? sxtah {rd,} rn, rm,{,ror #} extend 16 bits to 32 and add ? sxtb16 {rd,} rm {,ror #n} signed extend byte 16 ? sxtb {rd,} rm {,ror #n} sign extend a byte ? sxth {rd,} rm {,ror #n} sign extend a halfword ? tbb [rn, rm] table branch byte ? tbh [rn, rm, lsl #1] table branch halfword ? teq rn, op2 test equivalence n,z,c tst rn, op2 test n,z,c uadd16 {rd,} rn, rm unsigned add 16 ge uadd8 {rd,} rn, rm unsigned add 8 ge usax {rd,} rn, rm unsigned subtract and add with exchange ge table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 94 uhadd16 {rd,} rn, rm unsigned halving add 16 ? uhadd8 {rd,} rn, rm unsigned halving add 8 ? uhasx {rd,} rn, rm unsigned halving add and subtract with exchange ? uhsax {rd,} rn, rm unsigned halving subtract and add with exchange ? uhsub16 {rd,} rn, rm unsigned halving subtract 16 ? uhsub8 {rd,} rn, rm unsigned halving subtract 8 ? ubfx rd, rn, #lsb, #width unsigned bit field extract ? udiv {rd,} rn, rm unsigned divide ? umaal rdlo, rdhi, rn, rm unsigned multiply accumulate accumulate long (32 32 + 32 + 32), 64-bit result ? umlal rdlo, rdhi, rn, rm unsigned multiply with accumulate (32 32 + 64), 64-bit result ? umull rdlo, rdhi, rn, rm unsigned multiply (32 32), 64-bit result ? uqadd16 {rd,} rn, rm unsigned saturating add 16 ? uqadd8 {rd,} rn, rm unsigned saturating add 8 ? uqasx {rd,} rn, rm unsigned saturating add and subtract with exchange ? uqsax {rd,} rn, rm unsigned saturating subtract and add with exchange ? uqsub16 {rd,} rn, rm unsigned saturating subtract 16 ? uqsub8 {rd,} rn, rm unsigned saturating subtract 8 ? usad8 {rd,} rn, rm unsigned sum of absolute differences ? usada8 {rd,} rn, rm, ra unsigned sum of absolute differences and accumulate ? usat rd, #n, rm {,shift #s} unsigned saturate q usat16 rd, #n, rm unsigned saturate 16 q uasx {rd,} rn, rm unsigned add and subtract with exchange ge usub16 {rd,} rn, rm unsigned subtract 16 ge usub8 {rd,} rn, rm unsigned subtract 8 ge uxtab {rd,} rn, rm,{,ror #} rotate, extend 8 bits to 32 and add ? uxtab16 {rd,} rn, rm,{,ror #} rotate, dual extend 8 bits to 16 and add ? uxtah {rd,} rn, rm,{,ror #} rotate, unsigned extend and add halfword ? uxtb {rd,} rm {,ror #n} zero extend a byte ? uxtb16 {rd,} rm {,ror #n} unsigned extend byte 16 ? uxth {rd,} rm {,ror #n} zero extend a halfword ? vabs.f32 sd, sm floating-point absolute ? vadd.f32 {sd,} sn, sm floating-point add ? vcmp.f32 sd, compare two floating-point registers, or one floating-point register and zero fpscr vcmpe.f32 sd, compare two floating-point registers, or one floating-point register and zero with invalid operation check fpscr vcvt.s32.f32 sd, sm convert between floating-point and integer ? table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
95 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.2 cmsis functions iso/iec cannot directly access some co rtex-m4 instructions. this section des cribes intrinsic functions that can generate these instructions, provided by the cmis and that might be provided by a c compiler. if a c compiler vcvt.s16.f32 sd, sd, #fbits convert between floating-point and fixed point ? vcvtr.s32.f32 sd, sm convert between floating-point and integer with rounding ? vcvt.f32.f16 sd, sm converts half-precision value to single-precision ? vcvtt.f32.f16 sd, sm converts single-p recision register to half-precision ? vdiv.f32 {sd,} sn, sm floating-point divide ? vfma.f32 {sd,} sn, sm floating-point fused multiply accumulate ? vfnma.f32 {sd,} sn, sm floating-point fused negate multiply accumulate ? vfms.f32 {sd,} sn, sm floating-point fused multiply subtract ? vfnms.f32 {sd,} sn, sm floating-point fused negate multiply subtract ? vldm.f<32|64> rn{!}, list load mu ltiple extension registers ? vldr.f<32|64> , [rn] load an extension register from memory ? vlma.f32 {sd,} sn, sm floating-point multiply accumulate ? vlms.f32 {sd,} sn, sm floating-point multiply subtract ? vmov.f32 sd, #imm floating-point move immediate ? vmov sd, sm floating-point move register ? vmov sn, rt copy arm core register to single precision ? vmov sm, sm1, rt, rt2 copy 2 arm core registers to 2 single precision ? vmov dd[x], rt copy arm co re register to scalar ? vmov rt, dn[x] copy scalar to arm core register ? vmrs rt, fpscr move fpscr to arm core register or apsr n,z,c,v vmsr fpscr, rt move to fpscr from arm core register fpscr vmul.f32 {sd,} sn, sm floating-point multiply ? vneg.f32 sd, sm floating-point negate ? vnmla.f32 sd, sn, sm floating-point multiply and add ? vnmls.f32 sd, sn, sm floating-point multiply and subtract ? vnmul {sd,} sn, sm floa ting-point multiply ? vpop list pop extension registers ? vpush list push extension registers ? vsqrt.f32 sd, sm calculates floating-point square root ? vstm rn{!}, list floating-point register store multiple ? vstr.f<32|64> sd, [rn] stores an extension register to memory ? vsub.f<32|64> {sd,} sn, sm floating-point subtract ? wfe ? wait for event ? wfi ? wait for interrupt ? table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 96 does not support an appropriate intrinsic function, the user might have to use inline assembler to access some instructions. the cmsis provides the following intrinsic functions to generate instructio ns that iso/iec c code cannot directly access: the cmsis also provides a number of functions for accessing the special registers using mrs and msr instructions: table 12-14. cmsis functions to gene rate some cortex-m4 instructions instruction cmsis function cpsie i void __enable_irq(void) cpsid i void __disable_irq(void) cpsie f void __enable_fault_irq(void) cpsid f void __disable_fault_irq(void) isb void __isb(void) dsb void __dsb(void) dmb void __dmb(void) rev uint32_t __rev(uint32_t int value) rev16 uint32_t __rev16(uint32_t int value) revsh uint32_t __revsh( uint32_t int value) rbit uint32_t __rbit(uint32_t int value) sev void __sev(void) wfe void __wfe(void) wfi void __wfi(void) table 12-15. cmsis intrin sic functions to access the special registers special register access cmsis function primask read uint32_t __get_primask (void) write void __set_prim ask (uint32_t value) faultmask read uint32_t __get_faultmask (void write void __set_faultmask (uint32_t value) basepri read uint32_t __get_basepri (void) write void __set_basepri (uint32_t value) control read uint32_t __get_control (void) write void __set_control (uint32_t value) msp read uint32_t __get_msp (void) write void __set_msp (uint32_t topofmainstack) psp read uint32_t __get_psp (void) write void __set_psp (uint32_t topofprocstack)
97 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.3 instruction descriptions 12.6.3.1 operands an instruction operand can be an arm register, a constant , or another instruction-specific parameter. instructions act on the operands and often store the result in a destinat ion register. when there is a destination register in the instruction, it is usually sp ecified before the operands. operands in some instructions are flexible, can either be a register or a constant. see ?flexible second operand? . 12.6.3.2 restrictions when using pc or sp many instructions have re strictions on whether the program counter (pc) or stack pointer (sp) for the operands or destination register can be used. see instruction descriptions for more information. note: bit[0] of any address written to the pc with a bx, blx, ld m, ldr, or pop instruction must be 1 for correct execution, because this bit indicates the required instruction set, and the cortex-m4 processor only supports thumb instructions. 12.6.3.3 flexible second operand many general data processing instructions have a flexible second operand. this is shown as operand2 in the descriptions of the synt ax of each instruction. operand2 can be a: ? ?constant? ? ?register with optional shift? constant specify an operand2 constant in the form: # constant where constant can be: ? any constant that can be produced by shifting an 8-bi t value left by any number of bits within a 32-bit word ? any constant of the form 0x00xy00xy ? any constant of the form 0xxy00xy00 ? any constant of the form 0xxyxyxyxy. note: in the constants shown above, x and y are hexadecimal digits. in addition, in a small number of instructions, constant can take a wider range of values. these are described in the individual instruction descriptions. when an operand2 constant is us ed with the instructions movs, mv ns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to bit[31] of the constant, if the constant is greater than 255 and can be produced by shifting an 8-bit value. these instructions do not affect the carry flag if operand2 is any other constant. instruction substitution the assembler might be able to produce an equivalent inst ruction in cases where the user specifies a constant that is not permitted. for example, an a ssembler might assemble the instruction cmp rd , #0xfffffffe as the equivalent instruction cmn rd , #0x2. register with optional shift specify an operand2 register in the form: rm {, shift} where: rm is the register holding the data for the second operand. shift is an optional shift to be applied to rm . it can be one of:
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 98 asr # n arithmetic shift right n bits, 1 n 32. lsl # n logical shift left n bits, 1 n 31. lsr # n logical shift right n bits, 1 n 32. ror # n rotate right n bits, 1 n 31. rrx rotate right one bit, with extend. - if omitted, no shift occurs, equivalent to lsl #0. if the user omits the shift, or specifies lsl #0, the instruction uses the value in rm . if the user specifies a shift, the shift is applied to the value in rm , and the resulting 32-bit value is used by the instruction. however, the contents in the register rm remains unchanged. specifying a register with shift also updates the carry flag when used with certain instructions . for information on the shift operations and how they affect the carry flag, see ?flexible second operand? 12.6.3.4 shift operations register shift operations move the bits in a register left or right by a specified number of bits, the shift length . register shift can be performed: ? directly by the instructions asr, lsr, lsl, ror, and rrx, and the result is written to a destination register ? during the calculation of operand2 by the instructions that specify the second operand as a register with shift. see ?flexible second operand? . the result is used by the instruction. the permitted shift lengths depend on the shift type and the instruction. if the shift length is 0, no shift occurs. register shift operations update t he carry flag except when the specif ied shift length is 0. the following subsections describe the various shift operations and how they affect the carry flag. in these descriptions, rm is the register containing the value to be shifted, and n is the shift length. asr arithmetic shift right by n bits moves the left-hand 32-n bits of the register, rm , to the right by n places, into the right-hand 32-n bits of the result. and it copies the origi nal bit[31] of the register into the left-hand n bits of the result. see figure 12-8 . the asr #n operation can be used to divide the value in the register rm by 2 n , with the result being rounded towards negative-infinity. when the instruction is asrs or when asr #n is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry fl ag is updated to the last bit shifted out, bit[ n -1], of the register rm . ? if n is 32 or more, then all the bits in the result are set to the value of bit[31] of rm . ? if n is 32 or more and the carry flag is updated , it is updated to th e value of bit[31] of rm . figure 12-8. asr #3 lsr logical shift right by n bits moves the left-hand 32-n bits of the register rm, to the right by n places, into the right- hand 32-n bits of the result. and it sets th e left-hand n bits of the result to 0. see figure 12-9 .  


99 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the lsr #n operation can be used to divide the value in the register rm by 2 n , if the value is regarded as an unsigned integer. when the instruction is lsrs or when lsr #n is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to the last bit sh ifted out, bit[n-1], of the register rm. ? if n is 32 or more, then all the bits in the result are cleared to 0. ? if n is 33 or more and the carry flag is updated, it is updated to 0. figure 12-9. lsr #3 lsl logical shift left by n bits moves the right-hand 32-n bits of the register rm, to the left by n places, into the left-hand 32-n bits of the result; and it sets the right-hand n bits of the result to 0. see figure 12-10 . the lsl #n operation can be used to multiply the value in the register rm by 2 n , if the value is regarded as an unsigned integer or a two?s complement signed integer. overflow can occur without warning. when the instruction is lsls or when lsl #n, with non-zero n , is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carr y flag is updated to the last bit shifted out, bit[32- n ], of the register rm . these instructions do not affect the carry flag when used with lsl #0. ? if n is 32 or more, then all the bits in the result are cleared to 0. ? if n is 33 or more and the carry flag is updated, it is updated to 0. figure 12-10. lsl #3 ror rotate right by n bits moves the left-hand 32- n bits of the register rm , to the right by n places, into the right-hand 32-n bits of the result; and it moves the right-hand n bits of the register into the left-hand n bits of the result. see figure 12-11 . when the instruction is rors or when ror # n is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to the last bit rotation, bit[ n -1], of the register rm . ? if n is 32, then the value of the result is same as the value in rm , and if the carry flag is updated, it is updated to bit[31] of rm . ? ror with shift length, n , more than 32 is the same as ror with shift length n -32.  



  
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 100 figure 12-11. ror #3 rrx rotate right with extend moves the bits of the register rm to the right by one bit; and it copies the carry flag into bit[31] of the result. see figure 12-12 . when the instruction is rrxs or when rrx is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to bit[0] of the register rm . figure 12-12. rrx 12.6.3.5 address alignment an aligned access is an operation where a word-aligned address is used for a word, dual word, or multiple word access, or where a halfword-aligned address is used for a halfword access. byte ac cesses are always aligned. the cortex-m4 processor supports unaligned access only for the following instructions: ? ldr, ldrt ? ldrh, ldrht ? ldrsh, ldrsht ? str, strt ? strh, strht all other load and store instructions generate a usage fault exception if they perform an unaligned access, and therefore their accesses must be address-aligned . for more information about usage faults, see ?fault handling? . unaligned accesses are usually slower than aligned accesses. in addition, some memory regions might not support unaligned accesses. therefore, arm recommends that programmers ensure that accesses are aligned. to avoid accidental generation of unaligned accesses, use the unalign_trp bit in the configuration and control register to trap all unaligned ac cesses, see ?configuration and control register? . 12.6.3.6 pc-relative expressions a pc-relative expression or label is a symbol that represents the address of an instruction or literal data. it is represented in the instruction as the pc value plus or minus a numeric offset. the assembler calculates the required offset from the label and the address of the curr ent instruction. if the offset is too big, the assembler produces an error. ? for b, bl, cbnz, and cbz instructions, the value of the pc is the address of the current instruction plus 4 bytes.  


 

101 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? for all other instructions that use la bels, the value of the pc is the addr ess of the current instruction plus 4 bytes, with bit[1] of the result cleared to 0 to make it word-aligned. ? your assembler might permit other syntaxes for pc-relat ive expressions, such as a label plus or minus a number, or an expression of the form [pc, #number]. 12.6.3.7 conditional execution most data processing instructions can optionally update the condition flags in the application program status register (apsr) according to the resu lt of the operation, see ?application program status register? . some instructions update all flags, and some only update a subset. if a flag is not updated, the original value is preserved. see the instruction descr iptions for the flags they affect. an instruction can be executed conditionally, based on the condition flags set in an other instruction, either: ? immediately after the instruct ion that updated the flags ? after any number of intervening instructions that have not updated the flags. conditional execution is available by using conditional branches or by adding condition code suffixes to instructions. see table 12-16 for a list of the suffixes to add to instruct ions to make them co nditional instructions. the condition code suffix enables the processor to test a condition based on the flags. if the condition test of a conditional instruction fails, the instruction: ? does not execute ? does not write any value to its destination register ? does not affect any of the flags ? does not generate any exception. conditional instructions, except for conditional branches, must be inside an if-then instruction block. see ?it? for more information and restrictions when using the it in struction. depending on the vendor, the assembler might automatically insert an it instruction if there are conditiona l instructions outside the it block. the cbz and cbnz instructions are used to compare the valu e of a register against zero and branch on the result. this section describes: ? ?condition flags? ? ?condition code suffixes? . condition flags the apsr contains the fo llowing condition flags: n set to 1 when the result of the operat ion was negative, cleared to 0 otherwise. z set to 1 when the result of the operation was zero, cleared to 0 otherwise. c set to 1 when the operation resulted in a carry, cleared to 0 otherwise. v set to 1 when the operation caused overflow, cleared to 0 otherwise. for more information about the apsr, see ?program status register? . a carry occurs: ? if the result of an addition is greater than or equal to 2 32 ? if the result of a subtraction is positive or zero ? as the result of an inline barrel shifter op eration in a move or logical instruction. an overflow occurs when the sign of the result, in bit[ 31], does not match the sign of the result, had the operation been performed at infinite precision, for example: ? if adding two negative values results in a positive value ? if adding two positive values results in a negative value ? if subtracting a positive value from a negative value generates a positive value
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 102 ? if subtracting a negative value from a po sitive value generates a negative value. the compare operations are identical to subtracting, for cmp, or adding, fo r cmn, except that the result is discarded. see the instruction descriptions for more information. note: most instructions update the status flags only if the s su ffix is specified. see the instruction descriptions for more information. condition code suffixes the instructions that can be condit ional have an optional conditi on code, shown in syntax descriptions as {cond}. conditional execution requires a preceding it instruction. an instruction with a condition code is only executed if the condition code flags in the apsr meet the specif ied condition. table 12-16 shows the condition codes to use. a conditional execution can be used with the it instruction to reduce the number of branch instructions in code. table 12-16 also shows the relationship between condition code suffixes and the n, z, c, and v flags. absolute value the example below shows the use of a conditional instru ction to find the absolute value of a number. r0 = abs(r1). movs r0, r1 ; r0 = r1, setting flags it mi ; it instruction for the negative condition rsbmi r0, r1, #0 ; if negative, r0 = -r1 compare and update value the example below shows the use of cond itional instructions to update the va lue of r4 if the signed values r0 is greater than r1 and r2 is greater than r3. cmp r0, r1 ; compare r0 and r1, setting flags itt gt ; it instruction for the two gt conditions cmpgt r2, r3 ; if 'greater than', compare r2 and r3, setting flags movgt r4, r5 ; if still 'greater than', do r4 = r5 table 12-16. condition code suffixes suffix flags meaning eq z = 1 equal ne z = 0 not equal cs or hs c = 1 higher or same, unsigned cc or lo c = 0 lower, unsigned < mi n = 1 negative pl n = 0 positive or zero vs v = 1 overflow vc v = 0 no overflow hi c = 1 and z = 0 higher, unsigned > ls c = 0 or z = 1 lower or same, unsigned ge n = v greater than or equal, signed lt n != v less than, signed < gt z = 0 and n = v greater than, signed > le z = 1 and n != v less than or equal, signed al can have any value always. this is the default when no suffix is specified.
103 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.3.8 instruction width selection there are many instructions that can generate ei ther a 16-bit encoding or a 32-bit encoding depending on the operands and destination register spec ified. for some of these instruct ions, the user can force a specific instruction size by using an instructio n width suffix. the .w suffix forces a 32 -bit instruction en coding. the .n suffix forces a 16-bit instruction encoding. if the user specifies an instruction width suffix and the assembler cannot generate an instruction encoding of the requested width, it generates an error. note: in some cases, it might be necessary to specify the .w su ffix, for example if the operand is the label of an instruction or literal data, as in the case of branch instructions. this is because the assembler might not automatically generate the right size encoding. to use an instruction width suffix, place it immediately after the instruction mnemonic and condition code, if any. the example below shows instructions with the instruction width suffix. bcs.w label ; creates a 32-bit instruction even for a short ; branch adds.w r0, r0, r1 ; creates a 32-bit instruction even though the same ; operation can be done by a 16-bit instruction
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 104 12.6.4 memory access instructions the table below shows the me mory access instructions. table 12-17. memory access instructions mnemonic description adr load pc-relative address clrex clear exclusive ldm{mode} load multiple registers ldr{type} load register using immediate offset ldr{type} load register using register offset ldr{type}t load register with unprivileged access ldr load register using pc-relative address ldrd load register dual ldrex{type} load register exclusive pop pop registers from stack push push registers onto stack stm{mode} store multiple registers str{type} store register using immediate offset str{type} store register using register offset str{type}t store register with unprivileged access strex{type} store register exclusive
105 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.4.1 adr load pc-relative address. syntax adr{cond } rd, label where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. label is a pc-relative expression. see ?pc-relative expressions? . operation adr determines the address by adding an immediate value to the pc, and writes the result to the destination register. adr produces position-independent code, because the address is pc-relative. if adr is used to generate a target address for a bx or blx instruction, en sure that bit[0] of the address generated is set to 1 for correct execution. values of label must be within the range of ? 4095 to +4095 from the address in the pc. note: the user might have to use the .w suffix to get the maxi mum offset range or to generate addresses that are not word- aligned. see ?instruction width selection? . restrictions rd must not be sp and must not be pc. condition flags this instruction does not change the flags. examples adr r1, textmessage ; write address value of a location labelled as ; textmessage to r1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 106 12.6.4.2 ldr and str, immediate offset load and store with immediate offset, pre-indexed imme diate offset, or post-indexed immediate offset. syntax op{ type}{ cond} rt, [ rn {, # offset }] ; immediate offset op{ type}{ cond} rt, [ rn , #offset ]! ; pre-indexed op{ type}{ cond} rt, [ rn ], #offset ; post-indexed opd{cond } rt, rt2, [ rn {, # offset }] ; immediate offset, two words opd{cond } rt, rt2, [ rn , #offset ]! ; pre-indexed, two words opd{cond } rt, rt2, [ rn ], #offset ; post-indexed, two words where: op is one of: ldr load register. str store register. type is one of: b unsigned byte, zero extend to 32 bits on loads. sb signed byte, sign extend to 32 bits (ldr only). h unsigned halfword, zero extend to 32 bits on loads. sh signed halfword, sign extend to 32 bits (ldr only). - omit, for word. cond is an optional condition code, see ?conditional execution? . rt is the register to load or store. rn is the register on which the memory address is based. offset is an offset from rn . if offset is omitted, the addres s is the contents of rn . rt2 is the additional register to lo ad or store for two-word operations. operation ldr instructions load one or two registers with a value from memory. str instructions store one or two register values to memory. load and store instructions with immediate offset can use the following addressing modes: offset addressing the offset value is added to or subtracted from the address obtained from the register rn . the result is used as the address for the memory access. the register rn is unaltered. the assembly language syntax for this mode is: [ rn, # offset]
107 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 pre-indexed addressing the offset value is added to or subtracted from the address obtained from the register rn . the result is used as the address for the memory access and written back into the register rn . the assembly language syntax for this mode is: [ rn, # offset]! post-indexed addressing the address obtained from the register rn is used as the address for the memory access. the offset value is added to or subtracted from the address, and written back into the register rn . the assembly language syntax for this mode is: [ rn], # offset the value to load or store can be a byte, halfword, word , or two words. bytes and halfwords can either be signed or unsigned. see ?address alignment? . the table below shows the ranges of offset fo r immediate, pre-indexed and post-indexed forms. restrictions for load instructions: ? rt can be sp or pc for word loads only ? rt must be different from rt2 for two-word loads ? rn must be different from rt and rt2 in the pre-indexed or post-indexed forms. when rt is pc in a word load instruction: ? bit[0] of the loaded value mu st be 1 for correct execution ? a branch occurs to the address created by changing bit[0] of the loaded value to 0 ? if the instruction is conditi onal, it must be the last instruction in the it block. for store instructions: ? rt can be sp for word stores only ? rt must not be pc ? rn must not be pc ? rn must be different from rt and rt2 in the pre-indexed or post-indexed forms. condition flags these instructions do not change the flags. table 12-18. offset ranges instruction type immediate offset pre-indexed post-indexed word, halfword, signed halfword, byte, or signed byte -255 to 4095 -255 to 255 -255 to 255 two words multiple of 4 in the range -1020 to 1020 multiple of 4 in the range -1020 to 1020 multiple of 4 in the range -1020 to 1020
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 108 examples ldr r8, [r10] ; loads r8 from the address in r10. ldrne r2, [r5, #960]! ; loads (conditionally) r2 from a word ; 960 bytes above the address in r5, and ; increments r5 by 960. str r2, [r9,#const-struc] ; const-struc is an expression evaluating ; to a constant in the range 0-4095. strh r3, [r4], #4 ; store r3 as halfword data into address in ; r4, then increment r4 by 4 ldrd r8, r9, [r3, #0x20] ; load r8 from a word 32 bytes above the ; address in r3, and load r9 from a word 36 ; bytes above the address in r3 strd r0, r1, [r8], #-16 ; store r0 to address in r8, and store r1 to ; a word 4 bytes above the address in r8, ; and then decrement r8 by 16. 12.6.4.3 ldr and str, register offset load and store with register offset. syntax op{ type}{ cond} rt, [ rn , rm {, lsl #n}] where: op is one of: ldr load register. str store register. type is one of: b unsigned byte, zero extend to 32 bits on loads. sb signed byte, sign extend to 32 bits (ldr only). h unsigned halfword, zero extend to 32 bits on loads. sh signed halfword, sign extend to 32 bits (ldr only). - omit, for word. cond is an optional condition code, see ?conditional execution? . rt is the register to load or store. rn is the register on which the memory address is based. rm is a register containing a valu e to be used as the offset. lsl # n is an optional shift, with n in the range 0 to 3. operation ldr instructions load a regist er with a value from memory. str instructions store a register value into memory. the memory address to load from or store to is at an offset from the register rn . the offset is specified by the register rm and can be shifted left by up to 3 bits using lsl. the value to load or store can be a byte, halfword, or word. for load instructions, bytes and halfwords can either be signed or unsigned. see ?address alignment? . restrictions in these instructions: ? rn must not be pc
109 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? rm must not be sp and must not be pc ? rt can be sp only for word loads and word stores ? rt can be pc only for word loads. when rt is pc in a word load instruction: ? bit[0] of the loaded value must be 1 for correct exec ution, and a branch occurs to this halfword-aligned address ? if the instruction is conditi onal, it must be the last instruction in the it block. condition flags these instructions do not change the flags. examples str r0, [r5, r1] ; store value of r0 into an address equal to ; sum of r5 and r1 ldrsb r0, [r5, r1, lsl #1] ; read byte value from an address equal to ; sum of r5 and two times r1, sign extended it ; to a word value and put it in r0 str r0, [r1, r2, lsl #2] ; stores r0 to an address equal to sum of r1 ; and four times r2
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 110 12.6.4.4 ldr and str, unprivileged load and store with unprivileged access. syntax op{ type }t{cond} rt, [ rn {, # offset }] ; immediate offset where: op is one of: ldr load register. str store register. type is one of: b unsigned byte, zero extend to 32 bits on loads. sb signed byte, sign extend to 32 bits (ldr only). h unsigned halfword, zero extend to 32 bits on loads. sh signed halfword, sign extend to 32 bits (ldr only). - omit, for word. cond is an optional condition code, see ?conditional execution? . rt is the register to load or store. rn is the register on which the memory address is based. offset is an offset from rn and can be 0 to 255. if offset is omitted, the address is the value in rn . operation these load and store instructions perfo rm the same function as the memory access instructions with immediate offset, see ?ldr and str, immediate offset? . the difference is that these inst ructions have only unprivileged access even when used in privileged software. when used in unprivileged software, these instructions behave in exactly the same way as normal memory access instructions with immediate offset. restrictions in these instructions: ? rn must not be pc ? rt must not be sp and must not be pc. condition flags these instructions do not change the flags. examples strbteq r4, [r7] ; conditionally store least significant byte in ; r4 to an address in r7, with unprivileged access ldrht r2, [r2, #8] ; load halfword value from an address equal to ; sum of r2 and 8 into r2, with unprivileged access
111 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.4.5 ldr, pc-relative load register from memory. syntax ldr{type }{ cond} rt, label ldrd{cond } rt, rt2, label ; load two words where: type is one of: b unsigned byte, zero extend to 32 bits. sb signed byte, sign extend to 32 bits. h unsigned halfword, zero extend to 32 bits. sh signed halfword, sign extend to 32 bits. - omit, for word. cond is an optional condition code, see ?conditional execution? . rt is the register to load or store. rt2 is the second register to load or store. label is a pc-relative expression. see ?pc-relative expressions? . operation ldr loads a register with a value from a pc-relative memory address. the memory address is specified by a label or by an offset from the pc. the value to load or store can be a byte, halfword, or word. for load instructions, bytes and halfwords can either be signed or unsigned. see ?address alignment? . label must be within a limited range of the current instruct ion. the table below shows th e possible offsets between label and the pc. the user might have to use the .w suffix to get the maximum offset range. see ?instruction width selection? . restrictions in these instructions: ? rt can be sp or pc only for word loads ? rt2 must not be sp and must not be pc ? rt must be different from rt2. table 12-19. offset ranges instruction type offset range word, halfword, signed halfword, byte, signed byte -4095 to 4095 two words -1020 to 1020
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 112 when rt is pc in a word load instruction: ? bit[0] of the loaded value must be 1 for correct exec ution, and a branch occurs to this halfword-aligned address ? if the instruction is conditi onal, it must be the last instruction in the it block. condition flags these instructions do not change the flags. examples ldr r0, lookuptable ; load r0 with a word of data from an address ; labelled as lookuptable ldrsb r7, localdata ; load a byte value from an address labelled ; as localdata, sign extend it to a word ; value, and put it in r7 12.6.4.6 ldm and stm load and store multiple registers. syntax op{ addr_mode }{cond} rn {!}, reglist where: op is one of: ldm load multiple registers. stm store multiple registers. addr_mode is any one of the following: ia increment address after each access. this is the default. db decrement address before each access. cond is an optional condition code, see ?conditional execution? . rn is the register on which the memory addresses are based. ! is an optional writeback suffix. if ! is present, the final address, that is loaded from or stored to, is written back into rn . reglist is a list of one or more registers to be loaded or stored, enclosed in braces. it can contain register ranges. it must be comma separated if it contains more than one register or register range, see ?examples? . ldm and ldmfd are synonyms for ldmia. ldmfd refers to its use for popping data from full descending stacks. ldmea is a synonym for ldmdb, and refers to its use for popping data from empty ascending stacks. stm and stmea are synonyms for stmia. stmea refe rs to its use for pushing data onto empty ascending stacks. stmfd is s synonym for stmdb, and refers to it s use for pushing data onto full descending stacks operation ldm instructions load the registers in reglist with word values from memory addresses based on rn . stm instructions store the word values in the registers in reglist to memory addresses based on rn . for ldm, ldmia, ldmfd, stm, stmia, and stmea the memory addresses used for the accesses are at 4-byte intervals ranging from rn to rn + 4 * ( n -1), where n is the number of registers in reglist . the accesses happens in order of increasing register numbers, with the lowest num bered register using the lowest memory address and the
113 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 highest number register using the hi ghest memory address. if the writeback suffix is specified, the value of rn + 4 * ( n -1) is written back to rn . for ldmdb, ldmea, stmdb, and stmfd the memory addresses used for the accesses are at 4-byte intervals ranging from rn to rn - 4 * ( n -1), where n is the number of registers in reglist . the accesses happen in order of decreasing register numbers, with the highest numbered register using the highest memory address and the lowest number register using the lo west memory address. if the writeback suffix is specified, the value of rn - 4 * ( n -1) is written back to rn . the push and pop instructions can be expressed in this form. see ?push and pop? for details. restrictions in these instructions: ? rn must not be pc ? reglist must not contain sp ? in any stm instruction, reglist must not contain pc ? in any ldm instruction, reglist must not contain pc if it contains lr ? reglist must not contain rn if the writeback suffix is specified. when pc is in reglist in an ldm instruction: ? bit[0] of the value loaded to the pc must be 1 for corr ect execution, and a branch occurs to this halfword- aligned address ? if the instruction is conditi onal, it must be the last instruction in the it block. condition flags these instructions do not change the flags. examples ldm r8,{r0,r2,r9} ; ldmia is a synonym for ldm stmdb r1!,{r3-r6,r11,r12} incorrect examples stm r5!,{r5,r4,r9} ; value stored for r5 is unpredictable ldm r2, {} ; there must be at least one register in the list
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 114 12.6.4.7 push and pop push registers onto, and pop registers off a full-descending stack. syntax push{cond } reglist pop{cond } reglist where: cond is an optional condition code, see ?conditional execution? . reglist is a non-empty list of registers, enclosed in braces. it can contain register ranges. it must be comma separated if it contains more than one register or register range. push and pop are synonyms for stmdb and ldm (or ldmia) with the memory addresses for the access based on sp, and with the final address fo r the access written back to the sp . push and pop are the preferred mnemonics in these cases. operation push stores registers on the stack in order of decr easing the register numbers, with the highest numbered register using the highest memory address and the lowe st numbered register using the lowest memory address. pop loads registers from the stack in order of increas ing register numbers, with the lowest numbered register using the lowest memory address and the highest nu mbered register using the highest memory address. see ?ldm and stm? for more information. restrictions in these instructions: ? reglist must not contain sp ? for the push instruction, reglist must not contain pc ? for the pop instruction, reglist must not contain pc if it contains lr. when pc is in reglist in a pop instruction: ? bit[0] of the value loaded to the pc must be 1 for corr ect execution, and a branch occurs to this halfword- aligned address ? if the instruction is conditi onal, it must be the last instruction in the it block. condition flags these instructions do not change the flags. examples push {r0,r4-r7} push {r2,lr} pop {r0,r10,pc}
115 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.4.8 ldrex and strex load and store register exclusive. syntax ldrex{ cond} rt, [rn {, # offset}] strex{ cond} rd, rt, [ rn {, # offset}] ldrexb{ cond} rt, [rn ] strexb{ cond} rd, rt, [rn] ldrexh{ cond} rt, [rn ] strexh{ cond} rd, rt, [rn] where: cond is an optional condition code, see ?conditional execution? . rd is the destination register for the returned status. rt is the register to load or store. rn is the register on which the memory address is based. offset is an optional offset applied to the value in rn . if offset is omitted, the address is the value in rn . operation ldrex, ldrexb, and ldrexh load a word, byte, and halfword respectively from a memory address. strex, strexb, and strexh attempt to store a word, byte, and halfword respectively to a memory address. the address used in any store-exclusive instruction must be the same as the address in the most recently executed load-exclusive instru ction. the value stored by the store-exclusive instruction must also have the same data size as the value loaded by the preceding load-excl usive instruction. this mean s software must always use a load-exclusive instruction and a matching store-exclusive instruction to perf orm a synchronization operation, see ?synchronization primitives? . if an store-exclusive instruction performs the store, it writes 0 to its destination register. if it does not perform the store, it writes 1 to its desti nation register. if the store-exclusive instruct ion writes 0 to the destination register, it is guaranteed that no other process in the system has accessed the memory location between the load-exclusive and store-exclusive instructions. for reasons of performance, keep the number of instructions between corresponding load-exclusive and store- exclusive instruction to a minimum. the result of executing a store-exclusive instruction to an address that is different from that used in the preceding load-exclusive instruction is unpredictable. restrictions in these instructions: ? do not use pc ? do not use sp for rd and rt ? for strex, rd must be different from both rt and rn ? the value of offset must be a multiple of four in the range 0?1020. condition flags these instructions do not change the flags. examples mov r1, #0x1 ; initialize the ?lock taken? value try ldrex r0, [lockaddr] ; load the lock value cmp r0, #0 ; is the lock free?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 116 itt eq ; it instruction for strexeq and cmpeq strexeq r0, r1, [lockaddr] ; try and claim the lock cmpeq r0, #0 ; did this succeed? bne try ; no ? try again .... ; yes ? we have the lock 12.6.4.9 clrex clear exclusive. syntax clrex{ cond} where: cond is an optional condition code, see ?conditional execution? . operation use clrex to make the next strex, st rexb, or strexh instruct ion write a 1 to its destination register and fail to perform the store. it is useful in exception handler code to force the failure of the store exclusive if the exception occurs between a load exclusive instruction and the matching store exclusive instruction in a synchronization operation. see ?synchronization primitives? for more information. condition flags these instructions do not change the flags. examples clrex
117 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.5 general data processing instructions the table below shows the data processing instructions. table 12-20. data processing instructions mnemonic description adc add with carry add add addw add and logical and asr arithmetic shift right bic bit clear clz count leading zeros cmn compare negative cmp compare eor exclusive or lsl logical shift left lsr logical shift right mov move movt move top movw move 16-bit constant mvn move not orn logical or not orr logical or rbit reverse bits rev reverse byte order in a word rev16 reverse byte order in each halfword revsh reverse byte order in bo ttom halfword and sign extend ror rotate right rrx rotate right with extend rsb reverse subtract sadd16 signed add 16 sadd8 signed add 8 sasx signed add and subtract with exchange ssax signed subtract and add with exchange sbc subtract with carry shadd16 signed halving add 16 shadd8 signed halving add 8 shasx signed halving add and subtract with exchange shsax signed halving subtract and add with exchange
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 118 shsub16 signed halving subtract 16 shsub8 signed halving subtract 8 ssub16 signed subtract 16 ssub8 signed subtract 8 sub subtract subw subtract teq test equivalence tst test uadd16 unsigned add 16 uadd8 unsigned add 8 uasx unsigned add and subtract with exchange usax unsigned subtract and add with exchange uhadd16 unsigned halving add 16 uhadd8 unsigned halving add 8 uhasx unsigned halving add and subtract with exchange uhsax unsigned halving subt ract and add with exchange uhsub16 unsigned halving subtract 16 uhsub8 unsigned halving subtract 8 usad8 unsigned sum of absolute differences usada8 unsigned sum of absolute differences and accumulate usub16 unsigned subtract 16 usub8 unsigned subtract 8 table 12-20. data processing instructions (continued) mnemonic description
119 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.5.1 add, adc, sub, sbc, and rsb add, add with carry, subtract, subtract with carry, and reverse subtract. syntax op{s}{ cond} {rd,} rn , operand2 op{ cond} {rd,} rn, # imm12 ; add and sub only where: op is one of: add add. adc add with carry. sub subtract. sbc subtract with carry. rsb reverse subtract. s is an optional suffix. if s is specified, the cond ition code flags are updated on the result of the operation, see ?conditional execution? . cond is an optional condition code, see ?conditional execution? . rd is the destination register. if rd is omitted, the destination register is rn . rn is the register holding the first operand. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. imm12 is any value in the range 0?4095. operation the add instruction adds the value of operand2 or imm12 to the value in rn . the adc instruction adds the values in rn and operand2 , together with the carry flag. the sub instruction su btracts the value of operand2 or imm12 from the value in rn . the sbc instruction subtracts the value of operand2 from the value in rn . if the carry flag is clear, the result is reduced by one. the rsb instruction subtracts the value in rn from the value of operand2 . this is useful because of the wide range of options for operand2 . use adc and sbc to synthesiz e multiword arithmetic, see multiword arithmetic examples on. see also ?adr? . note: addw is equivalent to the add syntax that uses the imm12 operand. subw is equivalent to the sub syntax that uses the imm12 operand. restrictions in these instructions: ? operand2 must not be sp and must not be pc ? rd can be sp only in add and sub, and only with the additional restrictions: ? rn must also be sp ? any shift in operand2 must be limited to a maximum of 3 bits using lsl ? rn can be sp only in add and sub ? rd can be pc only in the add{ cond } pc, pc, rm instruction where: ? the user must not specify the s suffix ? rm must not be pc and must not be sp
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 120 ? if the instruction is conditi onal, it must be the last instruction in the it block ? with the exception of the add{ cond } pc, pc, rm instruction, rn can be pc only in add and sub, and only with the additional restrictions: ? the user must not specify the s suffix ? the second operand must be a constant in the range 0 to 4095. ? note: when using the pc for an addition or a subtraction, bits[1:0] of the pc are rounded to 0b00 before performing the calculatio n, making the base address for the calculation word-aligned. ? note: to generate the address of an instruction, the constant based on the value of the pc must be adjusted. arm recommends to use the adr instruction instead of add or sub with rn equal to the pc, because the assembler automati cally calculates the correct cons tant for the adr instruction. when rd is pc in the add{ cond } pc, pc, rm instruction: ? bit[0] of the value writte n to the pc is ignored ? a branch occurs to the address created by forcing bit[0] of that value to 0. condition flags if s is specified, these instructions update the n, z, c and v flags according to the result. examples add r2, r1, r3 ; sets the flags on the result subs r8, r6, #240 ; subtracts contents of r4 from 1280 rsb r4, r4, #1280 ; only executed if c flag set and z adchi r11, r0, r3 ; flag clear. multiword arithmetic examples the example below shows two instructions that add a 64-bit integer contained in r2 and r3 to another 64-bit integer contained in r0 and r1, and place the result in r4 and r5. 64-bit addition example adds r4, r0, r2 ; add the least significant words adc r5, r1, r3 ; add the most significant words with carry multiword values do not have to use consecutive register s. the example below shows in structions that subtract a 96-bit integer contained in r9, r1, and r11 from another contained in r6, r2, and r8. the example stores the result in r6, r9, and r2. 96-bit subtraction example subs r6, r6, r9 ; subtract the least significant words sbcs r9, r2, r1 ; subtract the middle words with carry sbc r2, r8, r11 ; subtract the most significant words with carry 12.6.5.2 and, orr, eor, bic, and orn logical and, or, exclusive or, bit clear, and or not. syntax op{s}{ cond} {rd,} rn , operand2 where: op is one of: and logical and. orr logical or, or bit set. eor logical exclusive or. bic logical and not, or bit clear. orn logical or not.
121 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 s is an optional suffix. if s is specified, the cond ition code flags are updated on the result of the operation, see ?conditional execution? . cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the register holding the first operand. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. operation the and, eor, and orr instructions perform bitwise and, exclusive or, and or operations on the values in rn and operand2 . the bic instruction performs an and operation on the bits in rn with the complements of the corresponding bits in the value of operand2 . the orn instruction performs an or operation on the bits in rn with the complements of the corresponding bits in the value of operand2 . restrictions do not use sp and do not use pc. condition flags if s is specified, these instructions: ? update the n and z flags according to the result ? can update the c flag during the calculation of operand2 , see ?flexible second operand? ? do not affect the v flag.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 122 examples and r9, r2, #0xff00 orreq r2, r0, r5 ands r9, r8, #0x19 eors r7, r11, #0x18181818 bic r0, r1, #0xab orn r7, r11, r14, ror #4 orns r7, r11, r14, asr #32 12.6.5.3 asr, lsl, lsr, ror, and rrx arithmetic shift right, logical shi ft left, logical shift right, rotate right, and rotate right with extend. syntax op{s}{ cond} rd, rm, rs op{s}{ cond} rd, rm, # n rrx{s}{ cond} rd, rm where: op is one of: asr arithmetic shift right. lsl logical shift left. lsr logical shift right. ror rotate right. s is an optional suffix. if s is specified, the cond ition code flags are updated on the result of the operation, see ?conditional execution? . rd is the destination register. rm is the register holding the value to be shifted. rs is the register holding the shift length to apply to the value in rm . only the least significant byte is used and can be in the range 0 to 255. n is the shift length. the range of shift length depends on the instruction: asr shift length from 1 to 32 lsl shift length from 0 to 31 lsr shift length from 1 to 32 ror shift length from 0 to 31 movs rd, rm is the preferred syntax for lsls rd, rm, #0. operation asr, lsl, lsr, and ror move the bits in the register rm to the left or right by the number of places specified by constant n or register rs . rrx moves the bits in register rm to the right by 1. in all these instructions, the result is written to rd , but the value in register rm remains unchanged. for details on what result is generated by the different instructions, see ?shift operations? . restrictions do not use sp and do not use pc. condition flags
123 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 if s is specified: ? these instructions update the n and z flags according to the result ? the c flag is updated to the last bit shifted out, except when the shift length is 0, see ?shift operations? . examples asr r7, r8, #9 ; arithmetic shift right by 9 bits sls r1, r2, #3 ; logical shift left by 3 bits with flag update lsr r4, r5, #6 ; logical shift right by 6 bits ror r4, r5, r6 ; rotate right by the value in the bottom byte of r6 rrx r4, r5 ; rotate right with extend. 12.6.5.4 clz count leading zeros. syntax clz{cond } rd, rm where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rm is the operand register. operation the clz instruction counts the number of leading zeros in the value in rm and returns the result in rd . the result value is 32 if no bits are set and zero if bit[31] is set. restrictions do not use sp and do not use pc. condition flags this instruction does not change the flags. examples clz r4,r9 clzne r2,r3
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 124 12.6.5.5 cmp and cmn compare and compare negative. syntax cmp{cond } rn, operand2 cmn{cond } rn, operand2 where: cond is an optional condition code, see ?conditional execution? . rn is the register holding the first operand. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. operation these instructions compare the value in a register with operand2 . they update the condition flags on the result, but do not write the result to a register. the cmp instruction subtracts the value of operand2 from the value in rn . this is the same as a subs instruction, except that the result is discarded. the cmn instruction adds the value of operand2 to the value in rn . this is the same as an adds instruction, except that the result is discarded. restrictions in these instructions: ? do not use pc ? operand2 must not be sp. condition flags these instructions update the n, z, c and v flags according to the result. examples cmp r2, r9 cmn r0, #6400 cmpgt sp, r7, lsl #2
125 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.5.6 mov and mvn move and move not. syntax mov{s}{ cond} rd, operand2 mov{cond } rd, #imm16 mvn{s}{ cond} rd, operand2 where: s is an optional suffix. if s is specified, the cond ition code flags are updated on the result of the operation, see ?conditional execution? . cond is an optional condition code, see ?conditional execution? . rd is the destination register. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. imm16 is any value in the range 0?65535. operation the mov instruction copies the value of operand2 into rd . when operand2 in a mov instruction is a register with a sh ift other than lsl #0, the preferred syntax is the corresponding shift instruction: ? asr{s}{cond} rd, rm, #n is the preferred syntax for mov{s}{cond} rd, rm, asr #n ? lsl{s}{cond} rd, rm, #n is the preferred sy ntax for mov{s}{cond} rd, rm, lsl #n if n != 0 ? lsr{s}{cond} rd, rm, #n is the preferred syntax for mov{s}{cond} rd, rm, lsr #n ? ror{s}{cond} rd, rm, #n is the preferre d syntax for mov{s}{cond} rd, rm, ror #n ? rrx{s}{cond} rd, rm is the preferred syntax for mov{s}{cond} rd, rm, rrx. also, the mov instruction permits additional forms of operand2 as synonyms for shift instructions: ? mov{s}{cond} rd, rm, asr rs is a synonym for asr{s}{cond} rd, rm, rs ? mov{s}{cond} rd, rm, lsl rs is a synonym for lsl{s}{cond} rd, rm, rs ? mov{s}{cond} rd, rm, lsr rs is a synonym for lsr{s}{cond} rd, rm, rs ? mov{s}{cond} rd, rm, ror rs is a synonym for ror{s}{cond} rd, rm, rs see ?asr, lsl, lsr, ror, and rrx? . the mvn instruction takes the value of operand2 , performs a bitwise logical not operation on the value, and places the result into rd . the movw instruction provides the same func tion as mov, but is restricted to using the imm16 operand. restrictions sp and pc only can be used in the mov inst ruction, with the follo wing restrictions: ? the second operand must be a register without shift ? the s suffix must not be specified. when rd is pc in a mov instruction: ? bit[0] of the value writte n to the pc is ignored ? a branch occurs to the address created by forcing bit[0] of that value to 0. though it is possible to use mov as a branch instruction, arm strongly recommends the use of a bx or blx instruction to branch fo r software portability to the arm instruction set. condition flags
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 126 if s is specified, these instructions: ? update the n and z flags according to the result ? can update the c flag during the calculation of operand2 , see ?flexible second operand? ? do not affect the v flag. examples movs r11, #0x000b ; write value of 0x000b to r11, flags get updated mov r1, #0xfa05 ; write value of 0xfa05 to r1, flags are not updated movs r10, r12 ; write value in r12 to r10, flags get updated mov r3, #23 ; write value of 23 to r3 mov r8, sp ; write value of stack pointer to r8 mvns r2, #0xf ; write value of 0xfffffff0 (bitwise inverse of 0xf) ; to the r2 and update flags. 12.6.5.7 movt move top. syntax movt{cond } rd, #imm16 where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. imm16 is a 16-bit immediate constant. operation movt writes a 16-bit immediate value, imm16 , to the top halfword, rd [31:16], of its destination register. the write does not affect rd [15:0]. the mov, movt instructio n pair enables to generate any 32-bit constant. restrictions rd must not be sp and must not be pc. condition flags this instruction does not change the flags. examples movt r3, #0xf123 ; write 0xf123 to upper halfword of r3, lower halfword ; and apsr are unchanged. 12.6.5.8 rev, rev16, revsh, and rbit reverse bytes and reverse bits. syntax op{ cond} rd, rn where: op is any of: rev reverse byte order in a word. rev16 reverse byte order in each halfword independently.
127 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 revsh reverse byte order in the bottom halfword, and sign extend to 32 bits. rbit reverse the bit order in a 32-bit word. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the register holding the operand. operation use these instructions to change endianness of data: rev converts either: ? 32-bit big-endian data into little-endian data ? 32-bit little-endian data into big-endian data. rev16 converts either: ? 16-bit big-endian data into little-endian data ? 16-bit little-endian data into big-endian data. revsh converts either: ? 16-bit signed big-endian data into 32-bit signed little-endian data ? 16-bit signed little-endian data into 32-bit signed big-endian data. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples rev r3, r7; reverse byte order of value in r7 and write it to r3 rev16 r0, r0; reverse byte order of each 16-bit halfword in r0 revsh r0, r5; reverse signed halfword revhs r3, r7; reverse with higher or same condition rbit r7, r8; reverse bit order of value in r8 and write the result to r7.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 128 12.6.5.9 sadd16 and sadd8 signed add 16 and signed add 8 syntax op{ cond}{ rd,} rn, rm where: op is any of: sadd16 performs two 16-bit signed integer additions. sadd8 performs four 8-bit signed integer additions. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first register holding the operand. rm is the second register holding the operand. operation use these instructions to perform a halfword or byte add in parallel: the sadd16 instruction: 1. adds each halfword from the first operand to the corresponding halfword of the second operand. 2. writes the result in the corresponding halfwords of the destination register. the sadd8 instruction: 1. adds each byte of the first operand to the corresponding byte of the second operand. writes the result in the corresponding bytes of the dest ination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples sadd16 r1, r0 ; adds the halfwords in r0 to the corresponding ; halfwords of r1 and writes to corresponding halfword ; of r1. sadd8 r4, r0, r5 ; adds bytes of r0 to the corresponding byte in r5 and ; writes to the corresponding byte in r4.
129 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.5.10shadd16 and shadd8 signed halving add 16 and signed halving add 8 syntax op{ cond}{ rd,} rn, rm where: op is any of: shadd16 signed halving add 16. shadd8 signed halving add 8. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation use these instructions to add 16-bit and 8-bit data and then to halve the result before writing the result to the destination register: the shadd16 instruction: 1. adds each halfword from the first operand to the corresponding halfword of the second operand. 2. shuffles the result by one bit to the right, halving the data. 3. writes the halfword results in the destination register. the shaddb8 instruction: 1. adds each byte of the first operand to the corresponding byte of the second operand. 2. shuffles the result by one bit to the right, halving the data. 3. writes the byte results in the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples shadd16 r1, r0 ; adds halfwords in r0 to corresponding halfword of r1 ; and writes halved result to corresponding halfword in ; r1 shadd8 r4, r0, r5 ; adds bytes of r0 to corresponding byte in r5 and ; writes halved result to corresponding byte in r4.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 130 12.6.5.11shasx and shsax signed halving add and subtract with exchange an d signed halving subtract and add with exchange. syntax op{cond} {rd}, rn, rm where: op is any of: shasx add and subtract wit h exchange an d halving. shsax subtract and add wit h exchange an d halving. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the shasx instruction: 1. adds the top halfword of the first operand with the bottom halfword of the second operand. 2. writes the halfword result of the addi tion to the top halfword of the destination register, shifted by one bit to the right causing a divide by two, or halving. 3. subtracts the top halfword of the second operand from the bottom highword of the first operand. 4. writes the halfword result of the division in the bott om halfword of the destination register, shifted by one bit to the right causing a divide by two, or halving. the shsax instruction: 1. subtracts the bottom halfword of the second operand from the top highword of the first operand. 2. writes the halfword result of the addition to the bottom halfword of the destination register, shifted by one bit to the right causing a divide by two, or halving. 3. adds the bottom halfword of the first operan d with the top halfword of the second operand. 4. writes the halfword result of the divi sion in the top halfword of the destination register, shifted by one bit to the right causing a divide by two, or halving. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags.
131 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 examples shasx r7, r4, r2 ; adds top halfword of r4 to bottom halfword of r2 ; and writes halved result to top halfword of r7 ; subtracts top halfword of r2 from bottom halfword of ; r4 and writes halved result to bottom halfword of r7 shsax r0, r3, r5 ; subtracts bottom halfword of r5 from top halfword ; of r3 and writes halved result to top halfword of r0 ; adds top halfword of r5 to bottom halfword of r3 and ; writes halved result to bottom halfword of r0.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 132 12.6.5.12shsub16 and shsub8 signed halving subtract 16 and signed halving subtract 8 syntax op{ cond}{ rd,} rn, rm where: op is any of: shsub16 signed halv ing subtract 16. shsub8 signed halving subtract 8. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation use these instructions to add 16-bit and 8-bit data and then to halve the result before writing the result to the destination register: the shsub16 instruction: 1. subtracts each halfword of the second operand from the corresponding halfwords of the first operand. 2. shuffles the result by one bit to the right, halving the data. 3. writes the halved halfword results in the destination register. the shsubb8 instruction: 1. subtracts each byte of the second operand from the corresponding byte of the first operand, 2. shuffles the result by one bit to the right, halving the data, 3. writes the corresponding signed byte results in the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples shsub16 r1, r0 ; subtracts halfwords in r0 from corresponding halfword ; of r1 and writes to corresponding halfword of r1 shsub8 r4, r0, r5 ; subtracts bytes of r0 from corresponding byte in r5, ; and writes to corresponding byte in r4.
133 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.5.13ssub16 and ssub8 signed subtract 16 and signed subtract 8 syntax op{ cond}{ rd,} rn, rm where: op is any of: ssub16 performs two 16-bit si gned integer subtractions. ssub8 performs four 8-bit signed integer subtractions. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation use these instructions to change endianness of data: the ssub16 instruction: 1. subtracts each halfword from the second operand from the corresponding halfword of the first operand 2. writes the difference result of two signed halfwords in the corresponding halfword of the destination register. the ssub8 instruction: 1. subtracts each byte of the second operand from the corresponding byte of the first operand 2. writes the difference result of four signed bytes in the corresponding byte of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples ssub16 r1, r0 ; subtracts halfwords in r0 from corresponding halfword ; of r1 and writes to corresponding halfword of r1 ssub8 r4, r0, r5 ; subtracts bytes of r5 from corresponding byte in ; r0, and writes to corresponding byte of r4.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 134 12.6.5.14sasx and ssax signed add and subtract with exchange and signed subtract and add with exchange. syntax op{cond} {rd}, rm, rn where: op is any of: sasx signed add and su btract with exchange. ssax signed subtract and add with exchange. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the sasx instruction: 1. adds the signed top halfword of the first operand wi th the signed bottom halfword of the second operand. 2. writes the signed result of the addition to the top halfword of the destination register. 3. subtracts the signed bottom halfword of the second operand from the top signed highword of the first operand. 4. writes the signed result of the subtraction to the bottom halfword of the destination register. the ssax instruction: 1. subtracts the signed bottom halfword of the second operand from the top signed highword of the first operand. 2. writes the signed result of the addition to the bottom halfword of the destination register. 3. adds the signed top halfword of the first operand with the signed bottom halfword of the second operand. 4. writes the signed result of the subtraction to the top halfword of t he destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples sasx r0, r4, r5 ; adds top halfword of r4 to bottom halfword of r5 and ; writes to top halfword of r0 ; subtracts bottom halfword of r5 from top halfword of r4 ; and writes to bottom halfword of r0 ssax r7, r3, r2 ; subtracts top halfword of r2 from bottom halfword of r3 ; and writes to bottom halfword of r7 ; adds top halfword of r3 with bottom halfword of r2 and ; writes to top halfword of r7. 12.6.5.15tst and teq test bits and test equivalence. syntax tst{cond } rn, operand2 teq{cond } rn, operand2 where
135 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 cond is an optional condition code, see ?conditional execution? . rn is the register holding the first operand. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. operation these instructions test the value in a register against operand2 . they update the condition flags based on the result, but do not write the result to a register. the tst instruction performs a bitwise and operation on the value in rn and the value of operand2 . this is the same as the ands instruction, except that it discards the result. to test whether a bit of rn is 0 or 1, use the tst instruction with an operand2 constant that has that bit set to 1 and all other bits cleared to 0. the teq instruction performs a bitwise exclusive or operation on the value in rn and the value of operand2 . this is the same as the eo rs instruction, except that it discards the result. use the teq instruction to test if two values are equal without affecting the v or c flags. teq is also useful for testing the sign of a value. after th e comparison, the n flag is the logical exclusive or of the sign bits of the two operands. restrictions do not use sp and do not use pc . condition flags these instructions: ? update the n and z flags according to the result ? can update the c flag during the calculation of operand2 , see ?flexible second operand? ? do not affect the v flag. examples tst r0, #0x3f8 ; perform bitwise and of r0 value to 0x3f8, ; apsr is updated but result is discarded teqeq r10, r9 ; conditionally test if value in r10 is equal to ; value in r9, apsr is updated but result is discarded. 12.6.5.16uadd16 and uadd8 unsigned add 16 and unsigned add 8 syntax op{ cond}{ rd,} rn, rm where: op is any of: uadd16 performs two 16-bit unsigned integer additions. uadd8 performs four 8-bit unsigned integer additions. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first register holding the operand. rm is the second register holding the operand. operation use these instructions to add 16- and 8-bit unsigned data:
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 136 the uadd16 instruction: 1. adds each halfword from the first operand to the corresponding halfword of the second operand. 2. writes the unsigned result in the corresp onding halfwords of the destination register. the uadd16 instruction: 1. adds each byte of the first operand to the corresponding byte of the second operand. 2. writes the unsigned result in the corresponding byte of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples uadd16 r1, r0 ; adds halfwords in r0 to corresponding halfword of r1, ; writes to corresponding halfword of r1 uadd8 r4, r0, r5 ; adds bytes of r0 to corresponding byte in r5 and ; writes to corresponding byte in r4.
137 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.5.17uasx and usax add and subtract with exchange and subtract and add with exchange. syntax op{cond} {rd}, rn, rm where: op is one of: uasx add and subtract with exchange. usax subtract and add with exchange. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the uasx instruction: 1. subtracts the top halfword of the second operand from the bottom halfword of the first operand. 2. writes the unsigned result from the subtraction to the bottom halfword of the destination register. 3. adds the top halfword of the first operand with the bottom halfword of the second operand. 4. writes the unsigned result of the addition to the top halfword of the destination register. the usax instruction: 1. adds the bottom halfword of the first operand with the top halfword of the second operand. 2. writes the unsigned result of the addition to the bottom halfwo rd of the destination register. 3. subtracts the bottom halfword of the second oper and from the top halfword of the first operand. 4. writes the unsigned result from the subtraction to the top halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples uasx r0, r4, r5 ; adds top halfword of r4 to bottom halfword of r5 and ; writes to top halfword of r0 ; subtracts bottom halfword of r5 from top halfword of r0 ; and writes to bottom halfword of r0 usax r7, r3, r2 ; subtracts top halfword of r2 from bottom halfword of r3 ; and writes to bottom halfword of r7 ; adds top halfword of r3 to bottom halfword of r2 and ; writes to top halfword of r7. 12.6.5.18uhadd16 and uhadd8 unsigned halving add 16 and unsigned halving add 8 syntax op{ cond}{ rd,} rn, rm where: op is any of: uhadd16 unsigned halving add 16. uhadd8 unsigned halving add 8.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 138 cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the register holding the first operand. rm is the register holding the second operand. operation use these instructions to add 16- and 8-bit data and then to halve the result before writing the result to the destination register: the uhadd16 instruction: 1. adds each halfword from the first operand to the corresponding halfword of the second operand. 2. shuffles the halfword result by one bit to the right, halving the data. 3. writes the unsigned results to the correspo nding halfword in the destination register. the uhadd8 instruction: 1. adds each byte of the first operand to the corresponding byte of the second operand. 2. shuffles the byte result by one bit to the right, halving the data. 3. writes the unsigned results in the corresponding byte in the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples uhadd16 r7, r3 ; adds halfwords in r7 to corresponding halfword of r3 ; and writes halved result to corresponding halfword ; in r7 uhadd8 r4, r0, r5 ; adds bytes of r0 to corresponding byte in r5 and ; writes halved result to corresponding byte in r4. 12.6.5.19uhasx and uhsax unsigned halving add and subtract with exchange and unsigned halving subtract and add with exchange. syntax op{cond} {rd}, rn, rm where: op is one of: uhasx add and subtract wit h exchange and halving. uhsax subtract and add wit h exchange and halving. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the uhasx instruction: 1. adds the top halfword of the first operand with the bottom halfword of the second operand. 2. shifts the result by one bit to the right causing a divide by two, or halving. 3. writes the halfword result of the addition to the top halfword of the destination register.
139 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 4. subtracts the top halfword of the second operand from the bottom highword of the first operand. 5. shifts the result by one bit to the right causing a divide by two, or halving. 6. writes the halfword result of the division in the bottom halfword of the destination register. the uhsax instruction: 1. subtracts the bottom halfword of the second operand from the top highword of the first operand. 2. shifts the result by one bit to the right causing a divide by two, or halving. 3. writes the halfword result of the subtraction in the top halfwo rd of the destination register. 4. adds the bottom halfword of the first operan d with the top halfword of the second operand. 5. shifts the result by one bit to the right causing a divide by two, or halving. 6. writes the halfword result of t he addition to the bottom halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples uhasx r7, r4, r2 ; adds top halfword of r4 with bottom halfword of r2 ; and writes halved result to top halfword of r7 ; subtracts top halfword of r2 from bottom halfword of ; r7 and writes halved result to bottom halfword of r7 uhsax r0, r3, r5 ; subtracts bottom halfword of r5 from top halfword of ; r3 and writes halved result to top halfword of r0 ; adds top halfword of r5 to bottom halfword of r3 and ; writes halved result to bottom halfword of r0.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 140 12.6.5.20uhsub16 and uhsub8 unsigned halving subtract 16 an d unsigned halving subtract 8 syntax op{ cond}{ rd,} rn, rm where: op is any of: uhsub16 performs two unsigned 16-bit integer additions, halves the results, and writes the results to the destination register. uhsub8 performs four unsigned 8-bit integer additions, halves the results, and writes the results to the destination register. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first register holding the operand. rm is the second register holding the operand. operation use these instructions to add 16-bit and 8-bit data and then to halve the result before writing the result to the destination register: the uhsub16 instruction: 1. subtracts each halfword of the second operand from the corresponding halfword of the first operand. 2. shuffles each halfword result to the right by one bit, halving the data. 3. writes each unsigned halfword result to the corr esponding halfwords in the destination register. the uhsub8 instruction: 1. subtracts each byte of second operand from the corresponding byte of the first operand. 2. shuffles each byte result by one bit to the right, halving the data. 3. writes the unsigned byte results to the co rresponding byte of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples uhsub16 r1, r0 ; subtracts halfwords in r0 from corresponding halfword of ; r1 and writes halved result to corresponding halfword in r1 uhsub8 r4, r0, r5 ; subtracts bytes of r5 from corresponding byte in r0 and ; writes halved result to corresponding byte in r4. 12.6.5.21sel select bytes. selects each byte of its result from ei ther its first operand or its second operand, according to the values of the ge flags. syntax sel{}{} {,} , where: c, q are standard assembler syntax fields. rd is the destination register.
141 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 rn is the first register holding the operand. rm is the second register holding the operand. operation the sel instruction: 1. reads the value of each bit of apsr.ge. 2. depending on the value of apsr.ge, assigns the destinati on register the value of either the first or second operand register. restrictions none. condition flags these instructions do not change the flags. examples sadd16 r0, r1, r2 ; set ge bits based on result sel r0, r0, r3 ; select bytes from r0 or r3, based on ge.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 142 12.6.5.22usad8 unsigned sum of absolute differences syntax usad8{ cond}{rd,} rn, rm where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation the usad8 instruction: 1. subtracts each byte of the second operand register from the corresponding byte of the first operand register. 2. adds the absolute values of the differences together. 3. writes the result to the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples usad8 r1, r4, r0 ; subtracts each byte in r0 from corresponding byte of r4 ; adds the differences and writes to r1 usad8 r0, r5 ; subtracts bytes of r5 from corresponding byte in r0, ; adds the differences and writes to r0.
143 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.5.23usada8 unsigned sum of absolute differences and accumulate syntax usada8{ cond}{rd,} rn , rm, ra where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. ra is the register that contains the accumulation value. operation the usada8 instruction: 1. subtracts each byte of the second operand register from the corresponding byte of the first operand register. 2. adds the unsigned absolute differences together. 3. adds the accumulation value to the sum of the absolute differences. 4. writes the result to the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples usada8 r1, r0, r6 ; subtracts bytes in r0 from corresponding halfword of r1 ; adds differences, adds value of r6, writes to r1 usada8 r4, r0, r5, r2 ; subtracts bytes of r5 from corresponding byte in r0 ; adds differences, adds value of r2 writes to r4.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 144 12.6.5.24usub16 and usub8 unsigned subtract 16 and unsigned subtract 8 syntax op{ cond}{ rd,} rn, rm where op is any of: usub16 unsigned subtract 16. usub8 unsigned subtract 8. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation use these instructions to subtract 16-bit and 8-bit data before writing the result to the destination register: the usub16 instruction: 1. subtracts each halfword from the second operand register from the corresponding halfword of the first operand register. 2. writes the unsigned result in the corresp onding halfwords of the destination register. the usub8 instruction: 1. subtracts each byte of the second operand register from the corresponding byte of the first operand register. 2. writes the unsigned byte result in the corr esponding byte of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples usub16 r1, r0 ; subtracts halfwords in r0 from corresponding halfword of r1 ; and writes to corresponding halfword in r1usub8 r4, r0, r5 ; subtracts bytes of r5 from corresponding byte in r0 and ; writes to the corresponding byte in r4.
145 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.6 multiply and divide instructions the table below shows the multip ly and divide instructions. table 12-21. multiply and divide instructions mnemonic description mla multiply with accumulate, 32-bit result mls multiply and subtract, 32-bit result mul multiply, 32-bit result sdiv signed divide smla[b,t] signed multiply accumulate (halfwords) smlad , smladx signed multiply accumulate dual smlal signed multiply with accumulate (32 32 + 64), 64-bit result smlal[b,t] signed multiply accumulate long (halfwords) smlald , smlaldx signed multiply accumulate long dual smlaw[b|t] signed multiply accumulate (word by halfword) smlsd signed multiply subtract dual smlsld signed multiply subtract long dual smmla signed most significant word multiply accumulate smmls , smmlsr signed most significant word multiply subtract smuad, smuadx signed dual multiply add smul[b,t] signed multiply (word by halfword) smmul , smmulr signed most significant word multiply smull signed multiply (32x32), 64-bit result smulwb, smulwt signed multiply (word by halfword) smusd, smusdx signed dual multiply subtract udiv unsigned divide umaal unsigned multiply accumulate accumulate long (32 32 + 32 + 32), 64-bit result umlal unsigned multiply with accumulate (32 32 + 64), 64-bit result umull unsigned multiply (32 32), 64-bit result
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 146 12.6.6.1 mul, mla, and mls multiply, multiply with accumulate, and multiply with subtract, us ing 32-bit operands, and producing a 32-bit result. syntax mul{s}{ cond} {rd,} rn , rm ; multiply mla{cond } rd, rn, rm , ra ; multiply with accumulate mls{cond } rd, rn, rm , ra ; multiply with subtract where: cond is an optional condition code, see ?conditional execution? . s is an optional suffix. if s is specified, the cond ition code flags are updated on the result of the operation, see ?conditional execution? . rd is the destination register. if rd is omitted, the destination register is rn . rn, rm are registers holding the values to be multiplied. ra is a register holding the value to be added or subtracted from. operation the mul instruction mult iplies the values from rn and rm , and places the least signific ant 32 bits of the result in rd . the mla instruction mult iplies the values from rn and rm , adds the value from ra , and places the least significant 32 bits of the result in rd . the mls instruction multiplies the values from rn and rm , subtracts the product from the value from ra , and places the least significant 32 bits of the result in rd . the results of these instructions do not depend on whether the operands are signed or unsigned. restrictions in these instructions, do not use sp and do not use pc. if the s suffix is used with the mul instruction: ? rd , rn , and rm must all be in the range r0 to r7 ? rd must be the same as rm ? the cond suffix must not be used. condition flags if s is specified, the mul instruction: ? updates the n and z flags according to the result ? does not affect the c and v flags. examples mul r10, r2, r5 ; multiply, r10 = r2 x r5 mla r10, r2, r1, r5 ; multiply with accumulate, r10 = (r2 x r1) + r5 muls r0, r2, r2 ; multiply with flag update, r0 = r2 x r2 mullt r2, r3, r2 ; conditionally multiply, r2 = r3 x r2 mls r4, r5, r6, r7 ; multiply with subtract, r4 = r7 - (r5 x r6) 12.6.6.2 umull, umaal, umlal unsigned long multiply, with optional accumulate, usin g 32-bit operands and producing a 64-bit result. syntax op{ cond} rdlo, rdhi, rn, rm where: op is one of:
147 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 umull unsigned long multiply. umaal unsigned long multiply with accumulate accumulate. umlal unsigned long mult iply, with accumulate. cond is an optional condition code, see ?conditional execution? . rdhi, rdlo are the destination registers. for umaal, umlal and umlal they also hold the accumulating value. rn, rm are registers holding the first and second operands. operation these instructions inte rpret the values from rn and rm as unsigned 32-bit integers. the umull instruction: ? multiplies the two unsigned integers in the first and second operands. ? writes the least significant 32 bits of the result in rdlo. ? writes the most significant 32 bits of the result in rdhi. the umaal instruction: ? multiplies the two unsigned 32-bit integers in the first and second operands. ? adds the unsigned 32-bit integer in rdhi to the 64-bit result of the multiplication. ? adds the unsigned 32-bit integer in rdlo to the 64-bit result of the addition. ? writes the top 32-bits of the result to rdhi. ? writes the lower 32-bit s of the result to rdlo . the umlal instruction: ? multiplies the two unsigned integers in the first and second operands. ? adds the 64-bit result to the 64-bit unsigned integer contained in rdhi and rdlo . ? writes the result back to rdhi and rdlo . restrictions in these instructions: ? do not use sp and do not use pc. ? rdhi and rdlo must be different registers. condition flags these instructions do not affect the condition code flags. examples umull r0, r4, r5, r6 ; multiplies r5 and r6, writes the top 32 bits to r4 ; and the bottom 32 bits to r0 umaal r3, r6, r2, r7 ; multiplies r2 and r7, adds r6, adds r3, writes the ; top 32 bits to r6, and the bottom 32 bits to r3 umlal r2, r1, r3, r5 ; multiplies r5 and r3, adds r1:r2, writes to r1:r2. 12.6.6.3 smla and smlaw signed multiply accumulate (halfwords). syntax op{xy}{ cond} rd, rn, rm op{y }{ cond} rd, rn, rm , ra where: op is one of: smla signed multiply accumulate long (halfwords).
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 148 x and y specifies which half of the source registers rn and rm are used as the first and second multiply operand. if x is b , then the bottom halfword, bits [15:0], of rn is used. if x is t , then the top halfword, bits [31:16], of rn is used. if y is b , then the bottom halfword, bits [15:0], of rm is used. if y is t , then the top halfword, bits [31:16], of rm is used smlaw signed multiply accumulate (word by halfword). y specifies which half of the source register rm is used as the second multiply operand. if y is t, then the top halfword, bits [31:16] of rm is used. if y is b, then the bottom halfword, bits [15:0] of rm is used. cond is an optional condition code, see ?conditional execution? . rd is the destination register. if rd is omitted, the destination register is rn . rn, rm are registers holding the values to be multiplied. ra is a register holding the value to be added or subtracted from. operation the smalbb, smlabt, smlatb , smlatt instructions: ? multiplies the specified signed halfword, top or bottom, values from rn and rm . ? adds the value in ra to the resulting 32-bit product. ? writes the result of the multiplication and addition in rd . the non-specified halfwords of the source registers are ignored. the smlawb and smlawt instructions: ? multiply the 32-bit signed values in rn with: ? the top signed halfword of rm , t instruction suffix. ? the bottom signed halfword of rm , b instruction suffix. ? add the 32-bit signed value in ra to the top 32 bits of the 48-bit product ? writes the result of the multiplication and addition in rd . the bottom 16 bits of the 48-bit product are ignored. if overflow occurs during the addition of the accumulate value, the instruct ion sets the q flag in the apsr. no overflow can occur during the multiplication. restrictions in these instructions, do not use sp and do not use pc. condition flags if an overflow is detected, the q flag is set. examples smlabb r5, r6, r4, r1 ; multiplies bottom halfwords of r6 and r4, adds ; r1 and writes to r5 smlatb r5, r6, r4, r1 ; multiplies top halfword of r6 with bottom halfword ; of r4, adds r1 and writes to r5 smlatt r5, r6, r4, r1 ; multiplies top halfwords of r6 and r4, adds ; r1 and writes the sum to r5 smlabt r5, r6, r4, r1 ; multiplies bottom halfword of r6 with top halfword ; of r4, adds r1 and writes to r5 smlabt r4, r3, r2 ; multiplies bottom halfword of r4 with top halfword of ; r3, adds r2 and writes to r4
149 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 smlawb r10, r2, r5, r3 ; multiplies r2 with bottom halfword of r5, adds ; r3 to the result and writes top 32-bits to r10 smlawt r10, r2, r1, r5 ; multiplies r2 with top halfword of r1, adds r5 ; and writes top 32-bits to r10.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 150 12.6.6.4 smlad signed multiply accu mulate long dual syntax op{x }{ cond} rd, rn, rm , ra ; where: op is one of: smlad signed multiply accumulate dual. smladx signed multiply accumulate dual reverse. x specifies which halfword of the source register rn is used as the multiply operand. if x is omitted, the multiplications are bottom bottom and top top. if x is present, the multiplications are bottom top and top bottom. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register holding the values to be multiplied. rm the second operand register. ra is the accumulate value. operation the smlad and smladx instructions regard the two operands as four halfword 16-bit values. the smlad and smladx instructions: ? if x is not present, multiply t he top signed halfword value in rn with the top signed halfword of rm and the bottom signed halfword values in rn with the bottom signed halfword of rm . ? or if x is present, multiply the top signed halfword value in rn with the bottom signed halfword of rm and the bottom signed halfword values in rn with the top signed halfword of rm . ? add both multiplication results to the signed 32-bit value in ra . ? writes the 32-bit signed result of the multiplication and addition to rd . restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples smlad r10, r2, r1, r5 ; multiplies two halfword values in r2 with ; corresponding halfwords in r1, adds r5 and ; writes to r10 smlaldx r0, r2, r4, r6 ; multiplies top halfword of r2 with bottom ; halfword of r4, multiplies bottom halfword of r2 ; with top halfword of r4, adds r6 and writes to ; r0. 12.6.6.5 smlal and smlald signed multiply accumulate long, si gned multiply accumulate long (halfwords) and signed multiply accumulate long dual. syntax op{ cond} rdlo, rdhi, rn, rm
151 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 op{xy}{ cond} rdlo, rdhi, rn, rm op{ x }{ cond} rdlo, rdhi, rn, rm where: op is one of: mlal signed multiply accumulate long. smlal signed multiply accumulate long (halfwords, x and y). x and y specify which halfword of the source registers rn and rm are used as the first and second multiply operand: if x is b, then the bottom halfword, bits [15:0], of rn is used. if x is t, then the top half word, bits [31:16], of rn is used. if y is b, then the bottom halfword, bits [15:0], of rm is used. if y is t, then the top halfword, bits [31:16], of rm is used. smlald signed multiply accumulate long dual. smlaldx signed multiply accumulate long dual reversed. if the x is omitted, the multiplications are bottom bottom and top top. if x is present, the multiplications are bottom top and top bottom. cond is an optional condition code, see ?conditional execution? . rdhi, rdlo are the dest ination registers. rdlo is the lower 32 bits and rdhi is the upper 32 bits of the 64-bit integer. for smlal, smlalbb, smlalbt, smlaltb, smlaltt, smlald and smla ldx, they also hold the accumulating value. rn, rm are registers holding the first and second operands. operation the smlal instruction: ? multiplies the two?s compleme nt signed word values from rn and rm . ? adds the 64-bit value in rdlo and rdhi to the resulting 64-bit product. ? writes the 64-bit result of t he multiplication and addition in rdlo and rdhi . the smlalbb, smlalbt, smlaltb and smlaltt instructions: ? multiplies the specified signed halfword, top or bottom, values from rn and rm . ? adds the resulting sign-extended 32-bit product to the 64-bit value in rdlo and rdhi . ? writes the 64-bit result of t he multiplication and addition in rdlo and rdhi . the non-specified halfwords of the source registers are ignored. the smlald and smlaldx instructions interpret the values from rn and rm as four halfword two?s complement signed 16-bit integers. these instructions: ? if x is not present, multiply t he top signed halfword value of rn with the top signed halfword of rm and the bottom signed halfword values of rn with the bottom signed halfword of rm . ? or if x is present, multiply the top signed halfword value of rn with the bottom signed halfword of rm and the bottom signed halfword values of rn with the top signed halfword of rm . ? add the two multiplication results to the signed 64-bit value in rdlo and rdhi to create the resulting 64-bit product. ? write the 64-bit product in rdlo and rdhi . restrictions in these instructions:
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 152 ? do not use sp and do not use pc. ? rdhi and rdlo must be different registers. condition flags these instructions do not affect the condition code flags. examples smlal r4, r5, r3, r8 ; multiplies r3 and r8, adds r5:r4 and writes to ; r5:r4 smlalbt r2, r1, r6, r7 ; multiplies bottom halfword of r6 with top ; halfword of r7, sign extends to 32-bit, adds ; r1:r2 and writes to r1:r2 smlaltb r2, r1, r6, r7 ; multiplies top halfword of r6 with bottom ; halfword of r7,sign extends to 32-bit, adds r1:r2 ; and writes to r1:r2 smlald r6, r8, r5, r1 ; multiplies top halfwords in r5 and r1 and bottom ; halfwords of r5 and r1, adds r8:r6 and writes to ; r8:r6 smlaldx r6, r8, r5, r1 ; multiplies top halfword in r5 with bottom ; halfword of r1, and bottom halfword of r5 with ; top halfword of r1, adds r8:r6 and writes to ; r8:r6.
153 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.6.6 smlsd and smlsld signed multiply subtract dual and signed multiply subtract long dual syntax op{ x }{ cond} rd, rn, rm , ra where: op is one of: smlsd signed multiply subtract dual. smlsdx signed multiply subtract dual reversed. smlsld signed multiply subtract long dual. smlsldx signed multiply subtract long dual reversed. smlaw signed multiply accumulate (word by halfword). if x is present, the multiplications are bottom top and top bottom. if the x is omitted, the multiplications are bottom bottom and top top. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. ra is the register holding the accumulate value. operation the smlsd instruction interprets the values from t he first and second operands as four signed halfwords. this instruction: ? optionally rotates the halfwords of the second operand. ? performs two signed 16 16-b it halfword multiplications. ? subtracts the result of the upper half word multiplication from the result of the lower halfword multiplication. ? adds the signed accumulate value to the result of the subtraction. ? writes the result of the addition to the destination register. the smlsld instruction inte rprets the values from rn and rm as four signed halfwords. this instruction: ? optionally rotates the halfwords of the second operand. ? performs two signed 16 16-b it halfword multiplications. ? subtracts the result of the upper half word multiplication from the result of the lower halfword multiplication. ? adds the 64-bit value in rdhi and rdlo to the result of the subtraction. ? writes the 64-bit result of the addition to the rdhi and rdlo . restrictions in these instructions: ? do not use sp and do not use pc. condition flags this instruction sets the q flag if the accumulate operation overfl ows. overflow cannot occur during the multiplications or subtraction. for the thumb instruction set, these instructions do not affect the condition code flags. examples smlsd r0, r4, r5, r6 ; multiplies bottom halfword of r4 with bottom ; halfword of r5, multiplies top halfword of r4
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 154 ; with top halfword of r5, subtracts second from ; first, adds r6, writes to r0 smlsdx r1, r3, r2, r0 ; multiplies bottom halfword of r3 with top ; halfword of r2, multiplies top halfword of r3 ; with bottom halfword of r2, subtracts second from ; first, adds r0, writes to r1 smlsld r3, r6, r2, r7 ; multiplies bottom halfword of r6 with bottom ; halfword of r2, multiplies top halfword of r6 ; with top halfword of r2, subtracts second from ; first, adds r6:r3, writes to r6:r3 smlsldx r3, r6, r2, r7 ; multiplies bottom halfword of r6 with top ; halfword of r2, multiplies top halfword of r6 ; with bottom halfword of r2, subtracts second from ; first, adds r6:r3, writes to r6:r3.
155 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.6.7 smmla and smmls signed most significant word multiply accumulate and signed most significant word multiply subtract syntax op{r }{ cond} rd, rn, rm , ra where: op is one of: smmla signed most significan t word multiply accumulate. smmls signed most significan t word multiply subtract. if the x is omitted, the multiplications are bottom bottom and top top. r is a rounding error flag. if r is specified, the result is rounded instead of being truncated. in this case the constant 0x 80000000 is added to the product before the high word is extracted. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the fi rst and second multiply operands. ra is the register holding the accumulate value. operation the smmla instruction interprets the values from rn and rm as signed 32-bit words. the smmla instruction: ? multiplies the values in rn and rm . ? optionally rounds the result by adding 0x80000000. ? extracts the most significant 32 bits of the result. ? adds the value of ra to the signed extracted value. ? writes the result of the addition in rd . the smmls instruction interprets the values from rn and rm as signed 32-bit words. the smmls instruction: ? multiplies the values in rn and rm . ? optionally rounds the result by adding 0x80000000. ? extracts the most significant 32 bits of the result. ? subtracts the extracted value of the result from the value in ra . ? writes the result of the subtraction in rd . restrictions in these instructions: ? do not use sp and do not use pc. condition flags these instructions do not affect the condition code flags. examples smmla r0, r4, r5, r6 ; multiplies r4 and r5, extracts top 32 bits, adds ; r6, truncates and writes to r0 smmlar r6, r2, r1, r4 ; multiplies r2 and r1, extracts top 32 bits, adds ; r4, rounds and writes to r6 smmlsr r3, r6, r2, r7 ; multiplies r6 and r2, extracts top 32 bits, ; subtracts r7, rounds and writes to r3
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 156 smmls r4, r5, r3, r8 ; multiplies r5 and r3, extracts top 32 bits, ; subtracts r8, truncates and writes to r4. 12.6.6.8 smmul signed most significant word multiply syntax op{r }{ cond} rd, rn, rm where: op is one of: smmul signed most significant word multiply. r is a rounding error flag. if r is specified, the result is rounded instead of being truncated. in this case the constant 0x 80000000 is added to the product before the high word is extracted. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the smmul instruction interprets the values from rn and rm as two?s complement 32-bit signed integers. the smmul instruction: ? multiplies the values from rn and rm . ? optionally rounds the result, otherwise truncates the result. ? writes the most significant signed 32 bits of the result in rd . restrictions in this instruction: ? do not use sp and do not use pc. condition flags this instruction does not affect the condition code flags. examples smull r0, r4, r5 ; multiplies r4 and r5, truncates top 32 bits ; and writes to r0 smullr r6, r2 ; multiplies r6 and r2, rounds the top 32 bits ; and writes to r6. 12.6.6.9 smuad and smusd signed dual multiply add and signed dual multiply subtract syntax op{x}{ cond} rd, rn, rm where: op is one of: smuad signed dual multiply add. smuadx signed dual multiply add reversed. smusd signed dual multiply subtract.
157 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 smusdx signed dual multip ly subtract reversed. if x is present, the multiplications are bottom top and top bottom. if the x is omitted, the multiplications are bottom bottom and top top. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the smuad instruction interprets the va lues from the first and second operands as two signed halfwords in each operand. this instruction: ? optionally rotates the halfwords of the second operand. ? performs two signed 16 16-bit multiplications. ? adds the two multiplication results together. ? writes the result of the addition to the destination register. the smusd instruction interprets the values from the first and second operands as two?s complement signed integers. this instruction: ? optionally rotates the halfwords of the second operand. ? performs two signed 16 16-bit multiplications. ? subtracts the result of the top halfword multiplication fr om the result of the bott om halfword multiplication. ? writes the result of the subtract ion to the destination register. restrictions in these instructions: ? do not use sp and do not use pc. condition flags sets the q flag if the addition overflow s. the multiplications cannot overflow.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 158 examples smuad r0, r4, r5 ; multiplies bottom halfword of r4 with the bottom ; halfword of r5, adds multiplication of top halfword ; of r4 with top halfword of r5, writes to r0 smuadx r3, r7, r4 ; multiplies bottom halfword of r7 with top halfword ; of r4, adds multiplication of top halfword of r7 ; with bottom halfword of r4, writes to r3 smusd r3, r6, r2 ; multiplies bottom halfword of r4 with bottom halfword ; of r6, subtracts multiplication of top halfword of r6 ; with top halfword of r3, writes to r3 smusdx r4, r5, r3 ; multiplies bottom halfword of r5 with top halfword of ; r3, subtracts multiplication of top halfword of r5 ; with bottom halfword of r3, writes to r4. 12.6.6.10smul and smulw signed multiply (halfwords) and signed multiply (word by halfword) syntax op{ xy}{ cond} rd,rn, rm op{ y }{ cond} rd. rn, rm for smulxy only: op is one of: smul{ xy } signed multiply (halfwords). x and y specify which halfword of the source registers rn and rm is used as the first and second multiply operand. if x is b, then the bottom halfword, bits [15:0] of rn is used. if x is t, then the top halfword, bits [31:16] of rn is used.if y is b, then the bot tom halfword, bits [15:0], of rm is used. if y is t, then the top halfword, bits [31:16], of rm is used. smulw{y} signed multiply (word by halfword). y specifies which halfword of the source register rm is used as the second mul tiply operand. if y is b, then the bottom halfword (bits [15:0]) of rm is used. if y is t, then the top halfword (bits [31:16]) of rm is used. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the smulbb, smultb, smulbt and smultt inst ructions interprets the values from rn and rm as four signed 16-bit integers. th ese instructions: ? multiplies the specified signed halfword, top or bottom, values from rn and rm . ? writes the 32-bit result of the multiplication in rd. the smulwt and smulwb instructio ns interprets th e values from rn as a 32-bit signed integer and rm as two halfword 16-bit signed integers. these instructions: ? multiplies the first operand and the top, t suffix, or the bottom, b suffix, halfword of the second operand. ? writes the signed most significant 32 bits of the 48-bit result in the destination register. restrictions
159 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 in these instructions: ? do not use sp and do not use pc. ? rdhi and rdlo must be different registers. examples smulbt r0, r4, r5 ; multiplies the bottom halfword of r4 with the ; top halfword of r5, multiplies results and ; writes to r0 smulbb r0, r4, r5 ; multiplies the bottom halfword of r4 with the ; bottom halfword of r5, multiplies results and ; writes to r0 smultt r0, r4, r5 ; multiplies the top halfword of r4 with the top ; halfword of r5, multiplies results and writes ; to r0 smultb r0, r4, r5 ; multiplies the top halfword of r4 with the ; bottom halfword of r5, multiplies results and ; and writes to r0 smulwt r4, r5, r3 ; multiplies r5 with the top halfword of r3, ; extracts top 32 bits and writes to r4 smulwb r4, r5, r3 ; multiplies r5 with the bottom halfword of r3, ; extracts top 32 bits and writes to r4.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 160 12.6.6.11umull, umlal, smull, and smlal signed and unsigned long multiply, with optional accumu late, using 32-bit operands and producing a 64-bit result. syntax op{ cond} rdlo, rdhi, rn, rm where: op is one of: umull unsigned long multiply. umlal unsigned long mult iply, with accumulate. smull signed long multiply. smlal signed long mult iply, with accumulate. cond is an optional condition code, see ?conditional execution? . rdhi, rdlo are the destination registers. for umlal and smlal they also hold the accu mulating value. rn, rm are registers holding the operands. operation the umull instruction inte rprets the values from rn and rm as unsigned integers. it multiplies these integers and places the least significant 32 bits of the result in rdlo , and the most significant 32 bits of the result in rdhi . the umlal instruction interprets the values from rn and rm as unsigned integers. it multiplies these integers, adds the 64-bit result to the 64-b it unsigned inte ger contained in rdhi and rdlo , and writes the result back to rdhi and rdlo . the smull instruction inte rprets the values from rn and rm as two?s complement signed integers. it multiplies these integers and places the least signi ficant 32 bits of the result in rdlo , and the most significant 32 bits of the result in rdhi. the smlal instruction interprets the values from rn and rm as two?s complement signed integers. it multiplies these integers, adds the 64-bit result to the 64-bit signed integer contained in rdhi and rdlo , and writes the result back to rdhi and rdlo . restrictions in these instructions: ? do not use sp and do not use pc ? rdhi and rdlo must be different registers. condition flags these instructions do not affect the condition code flags. examples umull r0, r4, r5, r6 ; unsigned (r4,r0) = r5 x r6 smlal r4, r5, r3, r8 ; signed (r5,r4) = (r5,r4) + r3 x r8
161 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.6.12sdiv and udiv signed divide and unsigned divide. syntax sdiv{cond } {rd,} rn, rm udiv{cond } {rd,} rn, rm where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. if rd is omitted, the destination register is rn . rn is the register holding the value to be divided. rm is a register holding the divisor. operation sdiv performs a signed integer division of the value in rn by the value in rm . udiv performs an unsigned integer division of the value in rn by the value in rm . for both instructions, if the value in rn is not divisible by the value in rm , the result is rounded towards zero. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples sdiv r0, r2, r4 ; signed divide, r0 = r2/r4 udiv r8, r8, r1 ; unsigned divide, r8 = r8/r1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 162 12.6.7 saturating instructions the table below shows the saturating instructions. for signed n -bit saturation, this means that: ? if the value to be saturated is less than -2 n - 1 , the result returned is -2 n-1 ? if the value to be saturated is greater than 2 n - 1 -1, the result returned is 2 n-1 -1 ? otherwise, the result returned is th e same as the value to be saturated. for unsigned n -bit saturation, this means that: ? if the value to be saturated is less than 0, the result returned is 0 ? if the value to be saturated is greater than 2 n -1, the result returned is 2 n -1 ? otherwise, the result returned is th e same as the value to be saturated. if the returned result is different from the value to be saturated, it is called saturation . if saturation occurs, the instruction sets the q flag to 1 in the apsr. otherwise, it leaves the q flag un changed. to cl ear the q flag to 0, the msr instruction must be used; see ?msr? . to read the state of the q flag, the mrs instruction must be used; see ?mrs? . table 12-22. saturating instructions mnemonic description ssat signed saturate ssat16 signed saturate halfword usat unsigned saturate usat16 unsigned saturate halfword qadd saturating add qsub saturating subtract qsub16 saturating subtract 16 qasx saturating add and subtract with exchange qsax saturating subtract and add with exchange qdadd saturating double and add qdsub saturating double and subtract uqadd16 unsigned saturating add 16 uqadd8 unsigned saturating add 8 uqasx unsigned saturating add and subtract with exchange uqsax unsigned saturating subt ract and add with exchange uqsub16 unsigned saturating subtract 16 uqsub8 unsigned saturating subtract 8
163 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.7.1 ssat and usat signed saturate and unsigned saturate to any bit position, with optional shift before saturating. syntax op{ cond} rd, #n , rm {, shift #s} where: op is one of: ssat saturates a signed va lue to a signed range. usat saturates a signed value to an unsigned range. cond is an optional condition code, see ?conditional execution? . rd is the destination register. n specifies the bit position to saturate to: n ranges from 1 n ranges from 0 to 31 for usat. to 32 for ssat rm is the register containing the value to saturate. shift #s is an optional shift applied to rm before saturating. it must be one of the following: asr #s where s is in the range 1 to 31. lsl #s where s is in the range 0 to 31. operation these instructions saturate to a signed or unsigned n -bit value. the ssat instruction applies th e specified shift, then sa turates to the signed range -2 n ?1 x 2 n ?1 -1. the usat instruction applies the specified shift, then saturates to the unsigned range 0 x 2 n -1. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. if saturation occurs, these instructions set the q flag to 1. examples ssat r7, #16, r7, lsl #4 ; logical shift left value in r7 by 4, then ; saturate it as a signed 16-bit value and ; write it back to r7 usatne r0, #7, r5 ; conditionally saturate value in r5 as an ; unsigned 7 bit value and write it to r0.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 164 12.6.7.2 ssat16 and usat16 signed saturate and unsigned saturate to any bit position for two halfwords. syntax op{ cond} rd, #n , rm where: op is one of: ssat16 saturates a signed halfword value to a signed range. usat16 saturates a signed halfword value to an unsigned range. cond is an optional condition code, see ?conditional execution? . rd is the destination register. n specifies the bit position to saturate to: n ranges from 1 n ranges from 0 to 15 for usat. to 16 for ssat rm is the register containing the value to saturate. operation the ssat16 instruction: saturates two signed 16-bit halfword va lues of the register with the value to saturate from selected by the bit position in n . writes the results as two signed 16-bit halfwords to the destination register. the usat16 instruction: saturates two unsigned 16-bit halfword values of the register with the value to saturate from selected by the bit position in n . writes the results as two unsigned ha lfwords in the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. if saturation occurs, these instructions set the q flag to 1. examples ssat16 r7, #9, r2 ; saturates the top and bottom highwords of r2 ; as 9-bit values, writes to corresponding halfword ; of r7 usat16ne r0, #13, r5 ; conditionally saturates the top and bottom ; halfwords of r5 as 13-bit values, writes to ; corresponding halfword of r0. 12.6.7.3 qadd and qsub saturating add and saturating subtract, signed. syntax op{cond} {rd}, rn, rm op{cond} {rd}, rn, rm where:
165 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 op is one of: qadd saturating 32-bit add. qadd8 saturating four 8-bit integer additions. qadd16 saturating two 16-bit integer additions. qsub saturating 32-bit subtraction. qsub8 saturating four 8-bit integer subtraction. qsub16 saturating two 16-bit integer subtraction. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation these instructions add or subtract two, four or eight values from the first and second operands and then writes a signed saturated value in the destination register. the qadd and qsub instructions apply the specified add or subtract, and then saturate the result to the signed range -2 n ?1 x 2 n ?1 -1, where x is given by the number of bits applied in the instruction, 32, 16 or 8. if the returned result is different from the value to be saturated, it is called saturation . if saturation occurs, the qadd and qsub instructions set the q fl ag to 1 in the apsr. othe rwise, it leaves the q flag unchanged . the 8-bit and 16-bit qadd and qsub instructions always leave the q flag unchanged. to clear the q flag to 0, the msr instruction must be used; see ?msr? . to read the state of the q flag, the mrs instruction must be used; see ?mrs? . restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. if saturation occurs, these instructions set the q flag to 1.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 166 examples qadd16 r7, r4, r2 ; adds halfwords of r4 with corresponding halfword of ; r2, saturates to 16 bits and writes to ; corresponding halfword of r7 qadd8 r3, r1, r6 ; adds bytes of r1 to the corresponding bytes of r6, ; saturates to 8 bits and writes to corresponding ; byte of r3 qsub16 r4, r2, r3 ; subtracts halfwords of r3 from corresponding ; halfword of r2, saturates to 16 bits, writes to ; corresponding halfword of r4 qsub8 r4, r2, r5 ; subtracts bytes of r5 from the corresponding byte ; in r2, saturates to 8 bits, writes to corresponding ; byte of r4. 12.6.7.4 qasx and qsax saturating add and subtract with exchange and sa turating subtract and add with exchange, signed. syntax op{cond} {rd}, rm, rn where: op is one of: qasx add and subtract with exchange and saturate. qsax subtract and add with exchange and saturate. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the qasx instruction: 1. adds the top halfword of the source operand with the bottom halfword of the second operand. 2. subtracts the top halfword of the second operand from the bottom highword of the first operand. 3. saturates the result of the subtraction and wr ites a 16-bit signed integer in the range ?2 15 x 2 15 ? 1, where x equals 16, to the bottom halfword of the destination register. 4. saturates the results of the sum and writes a 16-bit signed integer in the range ?2 15 x 2 15 ? 1, where x equals 16, to the top halfword of the destination register. the qsax instruction: 1. subtracts the bottom halfword of the second operand from the top highword of the first operand. 2. adds the bottom halfword of the source oper and with the top halfword of the second operand. 3. saturates the results of the sum and writes a 16-bit signed integer in the range ?2 15 x 2 15 ? 1, where x equals 16, to the bottom halfwo rd of the destination register. 4. saturates the result of the subtraction and wr ites a 16-bit signed integer in the range ?2 15 x 2 15 ? 1, where x equals 16, to the top halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples
167 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 qasx r7, r4, r2 ; adds top halfword of r4 to bottom halfword of r2, ; saturates to 16 bits, writes to top halfword of r7 ; subtracts top highword of r2 from bottom halfword of ; r4, saturates to 16 bits and writes to bottom halfword ; of r7 qsax r0, r3, r5 ; subtracts bottom halfword of r5 from top halfword of ; r3, saturates to 16 bits, writes to top halfword of r0 ; adds bottom halfword of r3 to top halfword of r5, ; saturates to 16 bits, writes to bottom halfword of r0.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 168 12.6.7.5 qdadd and qdsub saturating double and add and saturating double and subtract, signed. syntax op{ cond} {rd}, rm, rn where: op is one of: qdadd saturating double and add. qdsub saturating double and subtract. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rm, rn are registers holding the first and second operands. operation the qdadd instruction: ? doubles the second operand value. ? adds the result of the doubling to the signed saturated value in the first operand. ? writes the result to t he destination register. the qdsub instruction: ? doubles the second operand value. ? subtracts the doubled value from the signed saturated value in the first operand. ? writes the result to t he destination register. both the doubling and the addition or s ubtraction have their results saturated to the 32-bit signed integer range ? 2 31 x 2 31 ? 1. if saturation occurs in either oper ation, it sets the q flag in the apsr. restrictions do not use sp and do not use pc . condition flags if saturation occurs, these instructions set the q flag to 1. examples qdadd r7, r4, r2 ; doubles and saturates r4 to 32 bits, adds r2, ; saturates to 32 bits, writes to r7 qdsub r0, r3, r5 ; subtracts r3 doubled and saturated to 32 bits ; from r5, saturates to 32 bits, writes to r0.
169 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.7.6 uqasx and uqsax saturating add and subtract with exchange and satu rating subtract and add with exchange, unsigned. syntax op{cond} {rd}, rm, rn where: type is one of: uqasx add and subtract with exchange and saturate. uqsax subtract and add with exchange and saturate. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the uqasx instruction: 1. adds the bottom halfword of the source operand with the top halfword of the second operand. 2. subtracts the bottom halfword of the second oper and from the top highword of the first operand. 3. saturates the results of the sum and writes a 16-bit unsigned integer in the range 0 x 2 16 ? 1, where x equals 16, to the top halfword of the destination register. 4. saturates the result of the subtraction and writes a 16-bit unsigned integer in the range 0 x 2 16 ? 1, where x equals 16, to the bottom halfword of the destination register. the uqsax instruction: 1. subtracts the bottom halfword of the second operand from the top highword of the first operand. 2. adds the bottom halfword of the first operan d with the top halfword of the second operand. 3. saturates the result of the subtraction and writes a 16-bit unsigned integer in the range 0 x 2 16 ? 1, where x equals 16, to the top halfword of the destination register. 4. saturates the results of the addition and writes a 16-bit unsigned integer in the range 0 x 2 16 ? 1, where x equals 16, to the bottom halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 170 examples uqasx r7, r4, r2 ; adds top halfword of r4 with bottom halfword of r2, ; saturates to 16 bits, writes to top halfword of r7 ; subtracts top halfword of r2 from bottom halfword of ; r4, saturates to 16 bits, writes to bottom halfword of r7 uqsax r0, r3, r5 ; subtracts bottom halfword of r5 from top halfword of r3, ; saturates to 16 bits, writes to top halfword of r0 ; adds bottom halfword of r4 to top halfword of r5 ; saturates to 16 bits, writes to bottom halfword of r0. 12.6.7.7 uqadd and uqsub saturating add and saturating subtract unsigned. syntax op{ cond} {rd}, rn, rm op{ cond} {rd}, rn, rm where: op is one of: uqadd8 saturating four unsigned 8-bit integer additions. uqadd16 saturating two unsigned 16-bit integer additions. udsub8 saturating four unsigned 8-bit integer subtractions. uqsub16 saturating two unsigned 16-bit integer subtractions. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation these instructions add or subtract two or four va lues and then writes an unsigned saturated value in the destination register. the uqadd16 instruction: ? adds the respective top and bottom half words of the first and second operands. ? saturates the result of the additions for each halfwo rd in the destination register to the unsigned range 0 x 2 16 -1, where x is 16. the uqadd8 instruction: ? adds each respective byte of the first and second operands. ? saturates the result of the addition for each byte in the destination register to the unsigned range 0 x 2 8 - 1, where x is 8. the uqsub16 instruction: ? subtracts both halfwords of the second operand from the respective halfwords of the first operand. ? saturates the result of the differences in the destination register to the unsigned range 0 x 2 16 -1, where x is 16. the uqsub8 instructions: ? subtracts the respective by tes of the second operand from the respective bytes of the first operand. ? saturates the results of the differences for each byte in the destination register to the unsigned range 0 x 2 8 -1, where x is 8. restrictions
171 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples uqadd16 r7, r4, r2 ; adds halfwords in r4 to corresponding halfword in r2, ; saturates to 16 bits, writes to corresponding halfword of r7 uqadd8 r4, r2, r5 ; adds bytes of r2 to corresponding byte of r5, saturates ; to 8 bits, writes to corresponding bytes of r4 uqsub16 r6, r3, r0 ; subtracts halfwords in r0 from corresponding halfword ; in r3, saturates to 16 bits, writes to corresponding ; halfword in r6 uqsub8 r1, r5, r6 ; subtracts bytes in r6 from corresponding byte of r5, ; saturates to 8 bits, writes to corresponding byte of r1.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 172 12.6.8 packing and unpacking instructions the table below shows the instructions that operate on packing and unpacking data. table 12-23. packing and unpacking instructions mnemonic description pkh pack halfword sxtab extend 8 bits to 32 and add sxtab16 dual extend 8 bits to 16 and add sxtah extend 16 bits to 32 and add sxtb sign extend a byte sxtb16 dual extend 8 bits to 16 and add sxth sign extend a halfword uxtab extend 8 bits to 32 and add uxtab16 dual extend 8 bits to 16 and add uxtah extend 16 bits to 32 and add uxtb zero extend a byte uxtb16 dual zero extend 8 bits to 16 and add uxth zero extend a halfword
173 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.8.1 pkhbt and pkhtb pack halfword syntax op{cond} {rd}, rn, rm {, lsl # imm} op{cond} {rd}, rn, rm {, asr # imm} where: op is one of: pkhbt pack halfword, bottom and top with shift. pkhtb pack halfword, top and bottom with shift. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register rm is the second operand register holding the value to be optionally shifted. imm is the shift length. the type of shift length depends on the instruction: for pkhbt lsl a left shift with a shift length from 1 to 31, 0 means no shift. for pkhtb asr an arithmetic shift right with a shift length from 1 to 32, a shift of 32-bits is encoded as 0b00000. operation the pkhbt instruction: 1. writes the value of the bottom halfword of the first operand to the bottom halfword of the destination register. 2. if shifted, the shifted value of the second operand is written to the top halfword of the destination register. the pkhtb instruction: 1. writes the value of the top halfword of the first operand to the top halfword of the destination register. 2. if shifted, the shifted value of the second operand is written to the bottom halfword of the destination register. restrictions rd must not be sp and must not be pc. condition flags this instruction does not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 174 examples pkhbt r3, r4, r5 lsl #0 ; writes bottom halfword of r4 to bottom halfword of ; r3, writes top halfword of r5, unshifted, to top ; halfword of r3 pkhtb r4, r0, r2 asr #1 ; writes r2 shifted right by 1 bit to bottom halfword ; of r4, and writes top halfword of r0 to top ; halfword of r4. 12.6.8.2 sxt and uxt sign extend and zero extend. syntax op{cond} {rd,} rm {, ror #n } op{cond} {rd}, rm {, ror #n } where: op is one of: sxtb sign extends an 8-bit value to a 32-bit value. sxth sign extends a 16-bit value to a 32-bit value. sxtb16 sign extends two 8-bit values to two 16-bit values. uxtb zero extends an 8-bit value to a 32-bit value. uxth zero extends a 16-bit value to a 32-bit value. uxtb16 zero extends two 8-bit values to two 16-bit values. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rm is the register holding the value to extend. ror #n is one of: ror #8 value from rm is rotated right 8 bits. operation these instructions do the following: 1. rotate the value from rm right by 0, 8, 16 or 24 bits. 2. extract bits from the resulting value: ? sxtb extracts bits[7:0] and sign extends to 32 bits. ? uxtb extracts bits[7:0] and zero extends to 32 bits. ? sxth extracts bits[15:0] and sign extends to 32 bits. ? uxth extracts bits[15:0] and zero extends to 32 bits. ? sxtb16 extracts bits[7:0] and sign extends to 16 bits, and extracts bits [23:16] and sign extends to 16 bits. ? uxtb16 extracts bits[7:0] an d zero extends to 16 bits, and extracts bits [23:16] and zero extends to 16 bits. restrictions do not use sp and do not use pc. condition flags these instructions do not affect the flags.
175 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 examples sxth r4, r6, ror #16 ; rotates r6 right by 16 bits, obtains bottom halfword of ; of result, sign extends to 32 bits and writes to r4 uxtb r3, r10 ; extracts lowest byte of value in r10, zero extends, and ; writes to r3. 12.6.8.3 sxta and uxta signed and unsigned extend and add syntax op{ cond} {rd,} rn, rm {, ror #n } op{ cond} {rd,} rn, rm {, ror #n } where: op is one of: sxtab sign extends an 8-bit value to a 32-bit value and add. sxtah sign extends a 16-bit value to a 32-bit value and add. sxtab16 sign extends two 8-bit values to two 16-bit values and add. uxtab zero extends an 8-bit value to a 32-bit value and add. uxtah zero extends a 16-bit value to a 32-bit value and add. uxtab16 zero extends two 8-bit values to two 16-bit values and add. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the register holding the value to rotate and extend. ror #n is one of: ror #8 value from rm is rotated right 8 bits. ror #16 value from rm is rotated right 16 bits. ror #24 value from rm is rotated right 24 bits. if ror # n is omitted, no rotation is performed. operation these instructions do the following: 1. rotate the value from rm right by 0, 8, 16 or 24 bits. 2. extract bits from the resulting value: ? sxtab extracts bits[7:0] from rm and sign extends to 32 bits. ? uxtab extracts bits[7:0] from rm and zero extends to 32 bits. ? sxtah extracts bits[15:0] from rm and sign extends to 32 bits. ? uxtah extracts bits[15:0] from rm and zero extends to 32 bits. ? sxtab16 extracts bits[7:0] from rm and sign extends to 16 bits, and extracts bits [23:16] from rm and sign extends to 16 bits. ? uxtab16 extracts bits[7:0] from rm and zero extends to 16 bits, and extracts bits [23:16] from rm and zero extends to 16 bits. 3. adds the signed or zero extended value to the word or corresponding halfword of rn and writes the result in rd . restrictions
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 176 do not use sp and do not use pc. condition flags these instructions do not affect the flags. examples sxtah r4, r8, r6, ror #16 ; rotates r6 right by 16 bits, obtains bottom ; halfword, sign extends to 32 bits, adds ; r8,and writes to r4 uxtab r3, r4, r10 ; extracts bottom byte of r10 and zero extends ; to 32 bits, adds r4, and writes to r3.
177 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.9 bitfield instructions the table below shows the instructions that operate on adjacent sets of bits in registers or bitfields. table 12-24. packing and unpacking instructions mnemonic description bfc bit field clear bfi bit field insert sbfx signed bit field extract sxtb sign extend a byte sxth sign extend a halfword ubfx unsigned bit field extract uxtb zero extend a byte uxth zero extend a halfword
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 178 12.6.9.1 bfc and bfi bit field clear and bit field insert. syntax bfc{cond } rd, #lsb, # width bfi{cond } rd, rn, # lsb, #width where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the source register. lsb is the position of the least significant bit of the bitfield. lsb must be in the range 0 to 31. width is the width of the bitfield and must be in the range 1 to 32- lsb . operation bfc clears a bitfield in a register. it clears width bits in rd , starting at the low bit position lsb . other bits in rd are unchanged. bfi copies a bitfield into one register from another register. it replaces width bits in rd starting at the low bit position lsb , with width bits from rn starting at bit[0]. other bits in rd are unchanged. restrictions do not use sp and do not use pc. condition flags these instructions do not affect the flags. examples bfc r4, #8, #12 ; clear bit 8 to bit 19 (12 bits) of r4 to 0 bfi r9, r2, #8, #12 ; replace bit 8 to bit 19 (12 bits) of r9 with ; bit 0 to bit 11 from r2.
179 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.9.2 sbfx and ubfx signed bit field extract and unsigned bit field extract. syntax sbfx{cond } rd, rn, # lsb , #width ubfx{cond } rd, rn, # lsb , #width where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the source register. lsb is the position of the least significant bit of the bitfield. lsb must be in the range 0 to 31. width is the width of the bitfield and must be in the range 1 to 32- lsb . operation sbfx extracts a bitfield from one register, sign extends it to 32 bits, and writes the result to the destination register. ubfx extracts a bitfield from one register, zero extends it to 32 bits, and writes th e result to the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the flags. examples sbfx r0, r1, #20, #4 ; extract bit 20 to bit 23 (4 bits) from r1 and sign ; extend to 32 bits and then write the result to r0. ubfx r8, r11, #9, #10 ; extract bit 9 to bit 18 (10 bits) from r11 and zero ; extend to 32 bits and then write the result to r8.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 180 12.6.9.3 sxt and uxt sign extend and zero extend. syntax sxtextend { cond} {rd ,} rm {, ror #n} uxtextend { cond} {rd }, rm {, ror #n} where: extend is one of: b extends an 8-bit value to a 32-bit value. h extends a 16-bit value to a 32-bit value. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rm is the register holding the value to extend. ror #n is one of: ror #8 value from rm is rotated right 8 bits. ror #16 value from rm is rotated right 16 bits. ror #24 value from rm is rotated right 24 bits. if ror # n is omitted, no rotation is performed. operation these instructions do the following: 1. rotate the value from rm right by 0, 8, 16 or 24 bits. 2. extract bits from the resulting value: ? sxtb extracts bits[7:0] and sign extends to 32 bits. ? uxtb extracts bits[7:0] and zero extends to 32 bits. ? sxth extracts bits[15:0] and sign extends to 32 bits. ? uxth extracts bits[15:0] and zero extends to 32 bits. restrictions do not use sp and do not use pc. condition flags these instructions do not affect the flags. examples sxth r4, r6, ror #16 ; rotate r6 right by 16 bits, then obtain the lower ; halfword of the result and then sign extend to ; 32 bits and write the result to r4. uxtb r3, r10 ; extract lowest byte of the value in r10 and zero ; extend it, and write the result to r3.
181 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.10 branch and control instructions the table below shows the branch and control instructions. table 12-25. branch and control instructions mnemonic description bbranch bl branch with link blx branch indirect with link bx branch indirect cbnz compare and branch if non zero cbz compare and branch if zero it if-then tbb table branch byte tbh table branch halfword
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 182 12.6.10.1b, bl, bx, and blx branch instructions. syntax b{cond } label bl{cond} label bx{cond} rm blx{cond } rm where: b is branch (immediate). bl is branch with link (immediate). bx is branch indirect (register). blx is branch indirect with link (register). cond is an optional condition code, see ?conditional execution? . label is a pc-relative expression. see ?pc-relative expressions? . rm is a register that indicates an address to branch to. bit[0] of the value in rm must be 1, but the address to branch to is created by changing bit[0] to 0. operation all these instructions cause a branch to label , or to the address indicated in rm . in addition: ? the bl and blx instructions write the address of th e next instruction to lr (the link register, r14). ? the bx and blx instructions result in a usagefault exception if bit[0] of rm is 0. b cond label is the only conditional instruct ion that can be either inside or outside an it block. all other branch instructions must be condit ional inside an it block, and must be unconditional outside the it block, see ?it? . the table below shows the ranges fo r the various branch instructions. the .w suffix might be used to get the maximum branch range. see ?instruction width selection? . restrictions the restrictions are: ? do not use pc in the blx instruction ? for bx and blx, bit[0] of rm must be 1 for correct execution but a branch occurs to the target address created by changing bit[0] to 0 ? when any of these instructions is inside an it bloc k, it must be the last instruction of the it block. b cond is the only conditional instruction that is not required to be inside an it block. however, it has a longer branch range when it is inside an it block. table 12-26. branch ranges instruction branch range b label ? 16 mb to +16 mb b cond label (outside it block) ? 1 mb to +1 mb b cond label (inside it block) ? 16 mb to +16 mb bl{ cond } label ? 16 mb to +16 mb bx{cond } rm any value in register blx{cond } rm any value in register
183 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 condition flags these instructions do not change the flags. examples b loopa ; branch to loopa ble ng ; conditionally branch to label ng b.w target ; branch to target within 16mb range beq target ; conditionally branch to target beq.w target ; conditionally branch to target within 1mb bl func ; branch with link (call) to function func, return address ; stored in lr bx lr ; return from function call bxne r0 ; conditionally branch to address stored in r0 blx r0 ; branch with link and exchange (call) to a address stored in r0.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 184 12.6.10.2cbz and cbnz compare and branch on zero, compare and branch on non-zero. syntax cbz rn, label cbnz rn, label where: rn is the register holding the operand. label is the branch destination. operation use the cbz or cbnz instructions to avoid changing the condition code flags and to reduce the number of instructions. cbz rn, label does not change condition flags but is otherwise equivalent to: cmp rn, #0 beq label cbnz rn, label does not change condition flags but is otherwise equivalent to: cmp rn, #0 bne label restrictions the restrictions are: ? rn must be in the range of r0 to r7 ? the branch destination must be within 4 to 130 bytes after the instruction ? these instructions must not be used inside an it block. condition flags these instructions do not change the flags. examples cbz r5, target ; forward branch if r5 is zero cbnz r0, target ; forward branch if r0 is not zero
185 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.10.3it if-then condition instruction. syntax it{x { y { z }}} cond where: x specifies the condition switch for the second instruction in the it block. y specifies the condition s witch for the third instru ction in the it block. z specifies the condition switch for the fourth instruction in the it block. cond specifies the condition for the first instruction in the it block. the condition switch for the second, third and four th instruction in the it block can be either: t then. applies the condition cond to the instruction. e else. applies the inverse condition of cond to the instruction. it is possible to use al (the always condition) for cond in an it instruction. if this is done, all of the instructions in the it block must be unconditional, and each of x , y , and z must be t or omitted but not e. operation the it instruction makes up to four following instructions conditional. the conditions can be all the same, or some of them can be the logical inverse of the others. the cond itional instructions following the it instruction form the it block . the instructions in the it block, including an y branches, must specify the condition in the { cond } part of their syntax. the assembler might be able to generate the required it instructions for conditional instructions automatically, so that the user does not have to write them. see the assembler documentation for details. a bkpt instruction in an it block is always executed, ev en if its condition fails. exceptions can be taken between an it instruction and the corresponding it block, or within an it block. such an exception results in entry to the appropriate exception handler, with suitab le return information in lr and stacked psr. instructions designed for use for exception returns can be used as normal to return from the exception, and execution of the it block resumes correctly. this is th e only way that a pc-modifyi ng instruction is permitted to branch to an instruction in an it block. restrictions the following instructions are not permitted in an it block: ? it ? cbz and cbnz ? cpsid and cpsie. other restrictions when using an it block are: ? a branch or any instruction that modifies the pc must either be outside an it block or must be the last instruction inside the it block. these are: ? add pc, pc, rm ? mov pc, rm ? b, bl, bx, blx ? any ldm, ldr, or pop instruction that writes to the pc ? tbb and tbh ? do not branch to any instruction inside an it block, except when returning from an exception handler
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 186 ? all conditional inst ructions except b cond must be inside an it block. b cond can be either outside or inside an it block but has a larger branch range if it is inside one ? each instruction inside the it block must specify a conditi on code suffix that is either the same or logical inverse as for the other instructions in the block. your assembler might place extra restrictions on the use of it blocks, such as prohi biting the use of assembler directives within them. condition flags this instruction does not change the flags. example itte ne ; next 3 instructions are conditional andne r0, r0, r1 ; andne does not update condition flags addsne r2, r2, #1 ; addsne updates condition flags moveq r2, r3 ; conditional move cmp r0, #9 ; convert r0 hex value (0 to 15) into ascii ; ('0'-'9', 'a'-'f') ite gt ; next 2 instructions are conditional addgt r1, r0, #55 ; convert 0xa -> 'a' addle r1, r0, #48 ; convert 0x0 -> '0' it gt ; it block with only one conditional instruction addgt r1, r1, #1 ; increment r1 conditionally ittee eq ; next 4 instructions are conditional moveq r0, r1 ; conditional move addeq r2, r2, #10 ; conditional add andne r3, r3, #1 ; conditional and bne.w dloop ; branch instruction can only be used in the last ; instruction of an it block it ne ; next instruction is conditional add r0, r0, r1 ; syntax error: no condition code used in it block 12.6.10.4tbb and tbh table branch byte and table branch halfword. syntax tbb [rn, rm] tbh [rn, rm, lsl #1] where: rn is the register containing the addre ss of the table of branch lengths. if rn is pc, then the address of the table is the address of the byte immediately following the tbb or tbh instruction. rm is the index register. this contains an index into the table. for halfword tables, lsl #1 doubles the value in rm to form the right offset into the table.
187 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 operation these instructions cause a pc-relative forward branch usin g a table of single byte offsets for tbb, or halfword offsets for tbh. rn provides a pointer to the table, and rm supplies an index into the table. for tbb the branch offset is twice the unsi gned value of the byte returned from the table. and for tbh the branch offset is twice the unsigned value of the halfword returned from the table. the branch occurs to the address at that offset from the address of the byte immediately after the tbb or tbh instruction. restrictions the restrictions are: ? rn must not be sp ? rm must not be sp and must not be pc ? when any of these instructions is used inside an it bl ock, it must be the last instruction of the it block. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 188 examples adr.w r0, branchtable_byte tbb [r0, r1] ; r1 is the index, r0 is the base address of the ; branch table case1 ; an instruction sequence follows case2 ; an instruction sequence follows case3 ; an instruction sequence follows branchtable_byte dcb 0 ; case1 offset calculation dcb ((case2-case1)/2) ; case2 offset calculation dcb ((case3-case1)/2) ; case3 offset calculation tbh [pc, r1, lsl #1] ; r1 is the index, pc is used as base of the ; branch table branchtable_h dci ((casea - branchtable_h)/2) ; casea offset calculation dci ((caseb - branchtable_h)/2) ; caseb offset calculation dci ((casec - branchtable_h)/2) ; casec offset calculation casea ; an instruction sequence follows caseb ; an instruction sequence follows casec ; an instruction sequence follows
189 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11 floating-point instructions the table below shows the floating-point instructions. these instructions are only available if the fp u is included, and enabled, in the system. see ?enabling the fpu? for information about enabling the floating-point unit. table 12-27. floating-point instructions mnemonic description vabs floating-point absolute vadd floating-point add vcmp compare two floating-point registers, or one floating-point register and zero vcmpe compare two floating-point registers, or one fl oating-point register and zero with invalid operation check vcvt convert between floating-point and integer vcvt convert between floating-point and fixed point vcvtr convert between floating-point and integer with rounding vcvtb converts half-precision value to single-precision vcvtt converts single-precision register to half-precision vdiv floating-point divide vfma floating-point fused multiply accumulate vfnma floating-point fused negate multiply accumulate vfms floating-point fused multiply subtract vfnms floating-point fused negate multiply subtract vldm load multiple extension registers vldr loads an extension register from memory vlma floating-point multiply accumulate vlms floating-point multiply subtract vmov floating-point move immediate vmov floating-point move register vmov copy arm core register to single precision vmov copy 2 arm core registers to 2 single precision vmov copies between arm core register to scalar vmov copies between scalar to arm core register vmrs move to arm core register from floating-point system register vmsr move to floating-point system register from arm core register vmul multiply floating-point vneg floating-point negate vnmla floating-point multiply and add vnmls floating-point multiply and subtract vnmul floating-point multiply vpop pop extension registers
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 190 vpush push extension registers vsqrt floating-point square root vstm store multiple extension registers vstr stores an extension register to memory vsub floating-point subtract table 12-27. floating-point instructions (continued) mnemonic description
191 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.1vabs floating-point absolute. syntax vabs{cond }.f32 sd, sm where: cond is an optional condition code, see ?conditional execution? . sd, sm are the destination floating-point value and the operand floating-point value. operation this instruction: 1. takes the absolute value of the operand floating-point register. 2. places the results in the destination floating-point register. restrictions there are no restrictions. condition flags the floating-point instruction clears the sign bit. examples vabs.f32 s4, s6
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 192 12.6.11.2vadd floating-point add syntax vadd{cond }.f32 {sd,} sn, sm where: cond is an optional condition code, see ?conditional execution? . sd, is the destination floating-point value. sn, sm are the operand floating-point values. operation this instruction: 1. adds the values in the two floating-point operand registers. 2. places the results in the destination floating-point register. restrictions there are no restrictions. condition flags this instruction does not change the flags. examples vadd.f32 s4, s6, s7
193 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.3vcmp, vcmpe compares two floating-point registers, or one floating-point register and zero. syntax vcmp{e }{ cond }.f32 sd , sm vcmp{e }{ cond }.f32 sd , #0.0 where: cond is an optional condition code, see ?conditional execution? . e if present, any nan operand causes an invalid operation exception. otherwise, only a signaling nan causes the exception. sd is the floating-point operand to compare. sm is the floating-point operan d that is compared with. operation this instruction: 1. compares: ? two floating-point registers. ? one floating-point register and zero. 2. writes the result to the fpscr flags. restrictions this instruction can optionally raise an invalid operation exception if either operand is any type of nan . it always raises an invalid operation exception if either operand is a signaling nan . condition flags when this instruction wr ites the result to the fpscr flags, the values are normally transferred to the arm flags by a subsequent vmrs instruction, see ?? . examples vcmp.f32 s4, #0.0 vcmp.f32 s4, s2
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 194 12.6.11.4vcvt, vcvtr between floating-point and integer converts a value in a register from floating-point to a 32-bit integer. syntax vcvt{r }{ cond }.tm.f32 sd, sm vcvt{cond }.f32.tm sd , sm where: rif r is specified, the operation uses the rounding mode specified by the fpscr. if r is omitted. the operation uses the round towards zero rounding mode. cond is an optional condition code, see ?conditional execution? . tm is the data type for the operand. it must be one of: s32 signed 32- u32 unsigned 32-bit value. bit value. sd, sm are the destination regist er and the operand register. operation these instructions: 1. either ? converts a value in a register from floating-point value to a 32-bit integer. ? converts from a 32-bit integer to floating-point value. 2. places the result in a second register. the floating-point to integer operation normally uses the round towards zero rounding mode, but can optionally use the rounding mode specified by the fpscr . the integer to floating-point operation us es the rounding mode specified by the fpscr . restrictions there are no restrictions. condition flags these instructions do not change the flags.
195 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.5vcvt between floating-point and fixed-point converts a value in a register from floating-point to and from fixed-point. syntax vcvt{cond }.td.f32 sd , sd, #fbits vcvt{cond }.f32.td sd , sd, #fbits where: cond is an optional condition code, see ?conditional execution? . td is the data type for the fixed-point number. it must be one of: s16 signed 16-bit value. u16 unsigned 16-bit value. s32 signed 32-bit value. u32 unsigned 32-bit value. sd is the destination register and the operand register. fbits is the number of fraction bits in the fixed-point number: if td is s16 or u16, fbits must be in the range 0?16. if td is s32 or u32, fbits must be in the range 1?32. operation these instructions: 1. either ? converts a value in a register from floating-point to fixed-point. ? converts a value in a register from fixed-point to floating-point. 2. places the result in a second register. the floating-point values are single-precision. the fixed-point value can be 16-bit or 32-bit. conversions from fixed-point values take their operand from the low- order bits of the source register and ignore any remaining bits. signed conversions to fixed-point values sign-extend the result value to the destination register width. unsigned conversions to fixed-point values zero-extend the result value to the destination register width. the floating-point to fixed-point operation uses the round towards zero rounding mode. the fixed-point to floating- point operation uses the round to nearest rounding mode. restrictions there are no restrictions. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 196 12.6.11.6vcvtb, vcvtt converts between a half-precision value and a single-precision value. syntax vcvt{y }{ cond }.f32.f16 sd, sm vcvt{y }{ cond }.f16.f32 sd, sm where: y specifies which half of the operand register sm or destination register sd is used for the operand or destination: - if y is b, then the bottom half, bits [15:0], of sm or sd is used. - if y is t, then the top half, bits [31:16], of sm or sd is used. cond is an optional condition code, see ?conditional execution? . sd is the destination register. sm is the operand register. operation this instruction with the .f16.32 suffix: 1. converts the half-precision value in the top or bottom half of a single-precision. register to single-precision. 2. writes the result to a single-precision register. this instruction with the.f32.f16 suffix: 1. converts the value in a single-precision register to half-precision. 2. writes the result into the top or bottom half of a si ngle-precision register, preserving the other half of the target register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
197 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.7vdiv divides floating-point values. syntax vdiv{cond }.f32 {sd,} sn, sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination register. sn, sm are the operand registers. operation this instruction: 1. divides one floating-point value by another floating-point value. 2. writes the result to the float ing-point destination register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 198 12.6.11.8vfma, vfms floating-point fused multiply accumulate and subtract. syntax vfma{cond }.f32 {sd,} sn, sm vfms{cond }.f32 {sd,} sn, sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination register. sn, sm are the operand registers. operation the vfma instruction: 1. multiplies the floating-point values in the operand registers. 2. accumulates the results into the destination register. the result of the multiply is no t rounded before the accumulation. the vfms instruction: 1. negates the first operand register. 2. multiplies the floating-point values of the first and second operand registers. 3. adds the products to the destination register. 4. places the results in the destination register. the result of the multiply is not rounded before the addition. restrictions there are no restrictions. condition flags these instructions do not change the flags.
199 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.9vfnma, vfnms floating-point fused negate mult iply accumulate and subtract. syntax vfnma{ cond}.f32 {sd, } sn, sm vfnms{ cond}.f32 {sd, } sn, sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination register. sn, sm are the operand registers. operation the vfnma instruction: 1. negates the first floating-point operand register. 2. multiplies the first floating-point op erand with second floating-point operand. 3. adds the negation of the floating -point destination register to the product 4. places the result into the destination register. the result of the multiply is not rounded before the addition. the vfnms instruction: 1. multiplies the first floating-point operand with second floating-point operand. 2. adds the negation of the floating-point value in the destination register to the product. 3. places the result in the destination register. the result of the multiply is not rounded before the addition. restrictions there are no restrictions. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 200 12.6.11.10vldm floating-point load multiple syntax vldm{mode }{cond}{. size} rn{! }, list where: mode is the addressing mode: - ia increment after. the consecutive addresses start at the address speci fied in rn . - db decrement before. the consecutive addresses end just before the address specified in rn . cond is an optional condition code, see ?conditional execution? . size is an optional data size specifier. rn is the base register. the sp can be used ! is the command to the instruction to write a modified value back to rn . this is required if mode == db, and is optional if mode == ia. list is the list of extension registers to be loaded, as a list of consecutively numbered doubleword or singleword registers, separated by commas and surrounded by brackets. operation this instruction loads: ? multiple extension registers from c onsecutive memory locations using an address from an arm core register as the base address. restrictions the restrictions are: ? if size is present, it must be equal to the size in bits, 32 or 64, of the registers in list . ? for the base address, the sp can be used. in the arm instruction set, if ! is not specified the pc can be used. ? list must contain at least one register . if it contains doubleword registers, it must not contain more than 16 registers. ? if using the decrement before addressing mode, the write back flag, ! , must be appended to the base register specification. condition flags these instructions do not change the flags.
201 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.11vldr loads a single extension register from memory syntax vldr{cond }{.64} dd, [ rn{#imm}] vldr{cond }{.64} dd, label vldr{cond }{.64} dd , [pc, #imm}] vldr{cond }{.32} sd, [ rn {, #imm}] vldr{cond }{.32} sd, label vldr{cond }{.32} sd , [pc, #imm] where: cond is an optional condition code, see ?conditional execution? . 64, 32 are the optional data size specifiers. dd is the destination register for a doubleword load. sd is the destination register for a singleword load. rn is the base register. the sp can be used. imm is the + or - immediate offset used to form the address. permitted address values are multiples of 4 in the range 0 to 1020. label is the label of the literal data item to be loaded. operation this instruction: ? loads a single extension register from memory, using a base address from an arm core register, with an optional offset. restrictions there are no restrictions. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 202 12.6.11.12vlma, vlms multiplies two floating-point values, an d accumulates or subtracts the results. syntax vlma{cond }.f32 sd, sn , sm vlms{cond }.f32 sd, sn , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sn, sm are the operand floating-point values. operation the floating-point multiply accumulate instruction: 1. multiplies two floating-point values. 2. adds the results to the destination floating-point value. the floating-point multiply subtract instruction: 1. multiplies two floating-point values. 2. subtracts the products from the destination floating-point value. 3. places the results in the destination register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
203 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.13vmov immediate move floating-point immediate syntax vmov{cond }.f32 sd, # imm where: cond is an optional condition code, see ?conditional execution? . sd is the branch destination. imm is a floating-point constant. operation this instruction copies a constant value to a floating-point register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 204 12.6.11.14vmov register copies the contents of one register to another. syntax vmov{cond }.f64 dd, dm vmov{cond }.f32 sd, sm where: cond is an optional condition code, see ?conditional execution? . dd is the destination register, for a doubleword operation. dm is the source register, for a doubleword operation. sd is the destination register, for a singleword operation. sm is the source register, for a singleword operation. operation this instruction copies the contents of one floating-point register to another. restrictions there are no restrictions condition flags these instructions do not change the flags.
205 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.15vmov scalar to arm core register transfers one word of a doubleword floating- point register to an arm core register. syntax vmov{cond } rt, dn[ x ] where: cond is an optional condition code, see ?conditional execution? . rt is the destination arm core register. dn is the 64-bit doubleword register. x specifies which half of the doubleword register to use: - if x is 0, use lower half of doubleword register - if x is 1, use upper half of doubleword register. operation this instruction transfers: ? one word from the upper or lower half of a doublewo rd floating-point register to an arm core register. restrictions rt cannot be pc or sp. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 206 12.6.11.16vmov arm core register to single precision transfers a single-precision register to and from an arm core register. syntax vmov{cond } sn, rt vmov{cond } rt, sn where: cond is an optional condition code, see ?conditional execution? . sn is the single-precision floating-point register. rt is the arm core register. operation this instruction transfers: ? the contents of a single-precision r egister to an arm core register. ? the contents of an arm core register to a single-precision register. restrictions rt cannot be pc or sp. condition flags these instructions do not change the flags.
207 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.17vmov two arm core registers to two single precision transfers two consecutively number ed single-precision registers to and from two arm core registers. syntax vmov{cond } sm, sm1, rt , rt2 vmov{cond } rt, rt2, sm , sm where: cond is an optional condition code, see ?conditional execution? . sm is the first single-precision register. sm1 is the second single-precision register. this is the next single-p recision register after sm . rt is the arm core register that sm is transferre d to or from. rt2 is the the arm core register that sm1 is transferred to or from. operation this instruction transfers: ? the contents of two consecutively numbered single -precision registers to two arm core registers. ? the contents of two arm core registers to a pair of single-precision registers. restrictions ? the restrictions are: ? the floating-point registers must be contiguous, one after the other. ? the arm core registers do not have to be contiguous. ? rt cannot be pc or sp. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 208 12.6.11.18vmov arm core register to scalar transfers one word to a floating-point register from an arm core register. syntax vmov{cond }{.32} dd[x] , rt where: cond is an optional condition code, see ?conditional execution? . 32 is an optional data size specifier. dd[x] is the destination, where [x] defines which half of the doubleword is transferred, as follows: if x is 0, the lower half is extracted if x is 1, the upper half is extracted. rt is the source arm core register. operation this instruction transfers one word to the upper or lower half of a doubleword floating-point register from an arm core register. restrictions rt cannot be pc or sp. condition flags these instructions do not change the flags.
209 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.19vmrs move to arm core register from floating-point system register. syntax vmrs{cond } rt, fpscr vmrs{cond } apsr_nzcv , fpscr where: cond is an optional condition code, see ?conditional execution? . rt is the destination arm core regist er. this register can be r0?r14. apsr_nzcv transfer fl oating-point flags to the apsr flags. operation this instruction performs one of the following actions: ? copies the value of the fpscr to a general-purpose register. ? copies the value of the fpscr flag bits to the apsr n, z, c, and v flags . restrictions rt cannot be pc or sp. condition flags these instructions optionally change the flags: n, z, c, v
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 210 12.6.11.20vmsr move to floating-point system register from arm core register. syntax vmsr{cond } fpscr, rt where: cond is an optional condition code, see ?conditional execution? . rt is the general-purpose register to be transferred to the fpscr. operation this instruction moves the value of a general-purpose register to the fpscr. see ?floating-point status control register? for more information. restrictions the restrictions are: ? rt cannot be pc or sp. condition flags this instruction updates the fpscr.
211 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.21vmul floating-point multiply. syntax vmul{cond }.f32 {sd,} sn, sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sn, sm are the operand floating-point values. operation this instruction: 1. multiplies two floating-point values. 2. places the results in the destination register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 212 12.6.11.22vneg floating-point negate. syntax vneg{cond }.f32 sd, sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sm is the operand floating-point value. operation this instruction: 1. negates a floating-point value. 2. places the results in a second floating-point register. the floating-point instruction inverts the sign bit. restrictions there are no restrictions. condition flags these instructions do not change the flags.
213 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.23vnmla, vnmls, vnmul floating-point multiply with negat ion followed by add or subtract. syntax vnmla{ cond}.f32 sd, sn , sm vnmls{ cond}.f32 sd, sn , sm vnmul{ cond}.f32 {sd ,} sn, sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point register. sn, sm are the operand floating-point registers. operation the vnmla instruction: 1. multiplies two floating-point register values. 2. adds the negation of the floating-point value in the destination register to the negation of the product. 3. writes the result back to the destination register. the vnmls instruction: 1. multiplies two floating-point register values. 2. adds the negation of the floating-point value in the destination register to the product. 3. writes the result back to the destination register. the vnmul instruction: 1. multiplies together two floating-point register values. 2. writes the negation of the resu lt to the destination register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 214 12.6.11.24vpop floating-point extension register pop. syntax vpop{cond }{.size} list where: cond is an optional condition code, see ?conditional execution? . size is an optional data size specifier. if present, it must be equal to the size in bits, 32 or 64, of the registers in list . list is the list of extension registers to be loaded, as a list of consecutively numbered doubleword or singleword registers, separated by commas and surrounded by brackets. operation this instruction loads mult iple consecutive extension registers from the stack. restrictions the list must contain at least one regist er, and not more than sixteen registers. condition flags these instructions do not change the flags.
215 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.25vpush floating-point extension register push. syntax vpush{ cond}{.size} list where: cond is an optional condition code, see ?conditional execution? . size is an optional data size specifier. if present, it must be equal to the size in bits, 32 or 64, of the registers in list . list is a list of the extension registers to be stored, as a list of consecutively num bered doubleword or singleword registers, separated by commas and sur rounded by brackets. operation this instruction: ? stores multiple consecutive extension registers to the stack. restrictions the restrictions are: ? list must contain at least one regi ster, and not more than sixteen. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 216 12.6.11.26vsqrt floating-point square root. syntax vsqrt{ cond}.f32 sd, sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sm is the operand floating-point value. operation this instruction: ? calculates the square ro ot of the value in a floating-point register. ? writes the result to another floating-point register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
217 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.27vstm floating-point store multiple. syntax vstm{mode }{cond}{. size} rn{! }, list where: mode is the addressing mode: - ia increment after. the consecutive addresses start at the address speci fied in rn . this is the default and can be omitted. - db decrement before. the consecutive addresses end just before the address specified in rn . cond is an optional condition code, see ?conditional execution? . size is an optional data size specifier. if present, it must be equal to the size in bits, 32 or 64, of the registers in list . rn is the base register. the sp can be used ! is the function that causes the instruct ion to write a modified value back to rn . required if mode == db. list is a list of the extension registers to be stored, as a list of consecutively num bered doubleword or singleword registers, separated by commas and sur rounded by brackets. operation this instruction: ? stores multiple extension registers to consecutive memory locations using a base address from an arm core register. restrictions the restrictions are: ? list must contain at least one register. if it contains doubleword registers it mu st not contain more than 16 registers. ? use of the pc as rn is deprecated. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 218 12.6.11.28vstr floating-point store. syntax vstr{cond }{.32} sd, [ rn{, #imm}] vstr{cond }{.64} dd, [ rn{, #imm}] where cond is an optional condition code, see ?conditional execution? . 32, 64 are the optional data size specifiers. sd is the source register for a singleword store. dd is the source register for a doubleword store. rn is the base register. the sp can be used. imm is the + or - immediate offset used to form the address. values are multiples of 4 in the range 0?1020. imm can be omitted, meaning an offset of +0. operation this instruction: ? stores a single extension register to memory, using an address from an arm core register, with an optional offset, defined in imm . restrictions the restrictions are: ? the use of pc for rn is deprecated. condition flags these instructions do not change the flags.
219 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.11.29vsub floating-point subtract. syntax vsub{cond }.f32 {sd,} sn, sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sn, sm are the operand floating-point value. operation this instruction: 1. subtracts one floating-point value from another floating-point value. 2. places the results in the destination floating-point register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 220 12.6.12 miscellaneous instructions the table below shows the remaining cortex-m4 instructions. table 12-28. miscellaneous instructions mnemonic description bkpt breakpoint cpsid change processor state, disable interrupts cpsie change processor state, enable interrupts dmb data memory barrier dsb data synchronization barrier isb instruction synchronization barrier mrs move from special register to register msr move from register to special register nop no operation sev send event svc supervisor call wfe wait for event wfi wait for interrupt
221 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.12.1bkpt breakpoint. syntax bkpt #imm where: imm is an expression evaluating to an integer in the range 0?255 (8-bit value). operation the bkpt instruction causes the processor to enter debug state. debug tools can use this to investigate system state when the instruction at a particular address is reached. imm is ignored by the processor. if required, a debugger can use it to store additional information about the breakpoint. the bkpt instruction can be placed inside an it block, bu t it executes unconditionally, unaffected by the condition specified by the it instruction. condition flags this instruction does not change the flags. examples bkpt 0xab ; breakpoint with immediate value set to 0xab (debugger can ; extract the immediate value by locating it using the pc) note: arm does no t recommend the use of the bkpt instruction with an immediate va lue set to 0xab for any purpose other than semi-hosting. 12.6.12.2cps change processor state. syntax cpseffect iflags where: effect is one of: ie clears the special purpose register. id sets the special purpose register. iflags is a sequence of one or more flags: i set or clear primask. f set or clear faultmask. operation cps changes the primask and faultm ask special register values. see ?exception mask registers? for more information about these registers. restrictions the restrictions are: ? use cps only from privileged software, it has no effect if used in unprivileged software ? cps cannot be conditional and so must not be used inside an it block.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 222 condition flags this instruction does not change the condition flags. examples cpsid i ; disable interrupts and configurable fault handlers (set primask) cpsid f ; disable interrupts and all fault handlers (set faultmask) cpsie i ; enable interrupts and configurable fault handlers (clear primask) cpsie f ; enable interrupts and fault handlers (clear faultmask) 12.6.12.3dmb data memory barrier. syntax dmb{cond } where: cond is an optional condition code, see ?conditional execution? . operation dmb acts as a data memory barrier. it ensures that al l explicit memory accesses that appear, in program order, before the dmb instruction are completed before any expl icit memory accesses that appear, in program order, after the dmb instruction. dmb does not affect the ordering or execution of instructions that do not access memory. condition flags this instruction does not change the flags. examples dmb ; data memory barrier
223 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.12.4dsb data synchronization barrier. syntax dsb{cond } where: cond is an optional condition code, see ?conditional execution? . operation dsb acts as a special data synchronization memory barri er. instructions that come after the dsb, in program order, do not execute until the dsb instruction completes. the dsb instruction complete s when all explicit memory accesses before it complete. condition flags this instruction does not change the flags. examples dsb ; data synchronisation barrier 12.6.12.5isb instruction synchronization barrier. syntax isb{cond } where: cond is an optional condition code, see ?conditional execution? . operation isb acts as an instruction synchronization barrier. it flushes the pipeline of the processor, so that all instructions following the isb are fetched from memory again, after the isb instruction has been completed. condition flags this instruction does not change the flags. examples isb ; instruction synchronisation barrier
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 224 12.6.12.6mrs move the contents of a special register to a general-purpose register. syntax mrs{cond } rd, spec_reg where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. spec_reg can be any of: apsr, ipsr, epsr, iepsr, iapsr, eapsr, psr, msp, psp, primask, basepri, basepri_max, faultmask, or control. operation use mrs in combination with msr as part of a read-m odify-write sequence for updating a psr, for example to clear the q flag. in process swap code, the programmers model state of the process being swapped out must be saved, including relevant psr contents. similarly, the state of the process being swapped in must also be restored. these operations use mrs in the st ate-saving instruction sequence and msr in the state-restoring instruction sequence. note: basepri_max is an alias of basepri when used with the mrs instruction. see ?msr? . restrictions rd must not be sp and must not be pc. condition flags this instruction does not change the flags. examples mrs r0, primask ; read primask value and write it to r0 12.6.12.7msr move the contents of a general-purpose regi ster into the specified special register. syntax msr{cond } spec_reg, rn where: cond is an optional condition code, see ?conditional execution? . rn is the source register. spec_reg can be any of: apsr, ipsr, epsr, iepsr, iapsr, eapsr, psr, msp, psp, primask, basepri, basepri_max, faultmask, or control.
225 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 operation the register access operation in msr depends on the priv ilege level. unprivileged software can only access the apsr. see ?application program status register? . privileged software can a ccess all special registers. in unprivileged software writes to unallocated or execution state bits in the psr are ignored. note: when the user writ es to basepri_max, the instruction writes to basepri only if either: rn is non-zero and the current basepri value is 0 rn is non-zero and less th an the current basepri value. see ?mrs? . restrictions rn must not be sp and must not be pc. condition flags this instruction updates the flags explicitly based on the value in rn . examples msr control, r1 ; read r1 value and write it to the control register 12.6.12.8nop no operation. syntax nop{cond } where: cond is an optional condition code, see ?conditional execution? . operation nop does nothing. nop is not necessarily a time-consu ming nop. the processor might remove it from the pipeline before it reaches the execution stage. use nop for padding, for example to place the following instruction on a 64-bit boundary. condition flags this instruction does not change the flags. examples nop ; no operation
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 226 12.6.12.9sev send event. syntax sev{cond } where: cond is an optional condition code, see ?conditional execution? . operation sev is a hint instruction that causes an event to be signaled to all processors within a multiprocessor system. it also sets the local event register to 1, see ?power management? . condition flags this instruction does not change the flags. examples sev ; send event 12.6.12.10svc supervisor call. syntax svc{cond } # imm where: cond is an optional condition code, see ?conditional execution? . imm is an expression evaluating to an integer in the range 0-255 (8-bit value). operation the svc instruction causes the svc exception. imm is ignored by the processor. if required, it can be re trieved by the exception handler to determine what service is being requested. condition flags this instruction does not change the flags. examples svc 0x32 ; supervisor call (svc handler can extract the immediate value ; by locating it via the stacked pc)
227 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.6.12.11wfe wait for event. syntax wfe{cond } where: cond is an optional condition code, see ?conditional execution? . operation wfe is a hint instruction. if the event register is 0, wfe suspends execution until one of the following events occurs: ? an exception, unless masked by the exception mask registers or the current priority level ? an exception enters the pending state, if sev onpend in the system control register is set ? a debug entry request, if debug is enabled ? an event signaled by a peripheral or another processor in a multiprocessor system using the sev instruction. if the event register is 1, wfe clea rs it to 0 and returns immediately. for more information, see ?power management? . condition flags this instruction does not change the flags. examples wfe ; wait for event 12.6.12.12wfi wait for interrupt. syntax wfi{cond } where: cond is an optional condition code, see ?conditional execution? . operation wfi is a hint instruction that suspends exec ution until one of the following events occurs: ? an exception ? a debug entry request, regardless of whether debug is enabled. condition flags this instruction does not change the flags. examples wfi ; wait for interrupt
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 228 12.7 cortex-m4 co re peripherals 12.7.1 peripherals ? nested vectored inte rrupt controller (nvic) the nested vectored interrupt controller (nvic) is an embedded interrupt controller that supports low latency interrupt processing. see section 12.8 ?nested vectored interrupt controller (nvic)? . ? system control block (scb) the system control block (scb) is the programmers mo del interface to the processor. it provides system implementation information and system control, includin g configuration, control, and reporting of system exceptions. see section 12.9 ?system control block (scb)? . ? system timer (systick) the system timer, systick, is a 24-bit count-down timer. use this as a real time operating system (rtos) tick timer or as a simple counter. see section 12.10 ?system timer (systick)? . ? memory protection unit (mpu) the memory protection unit (mpu) impr oves system reliability by defining the memory attribut es for different memory regions. it provides up to eight different re gions, and an optional predefined background region. see section 12.11 ?memory protection unit (mpu)? . ? floating-point unit (fpu) the floating-point unit (fpu) provides ieee754-compliant operations on single-precision, 32-bit, floating- point values. see section 12.12 ?floating point unit (fpu)? . 12.7.2 address map the address map of the private peripheral bus (ppb) is given in the following table. in register descriptions: ? the required privilege gives the privilege level required to access the register, as follows: ? privileged: only privileged soft ware can access the register. ? unprivileged: both unprivileged and privil eged software can access the register. table 12-29. core periph eral register regions address core peripheral 0xe000e008?0xe000e00f system control block 0xe000e010?0xe000e01f system timer 0xe000e100?0xe000e4ef nested vectored interrupt controller 0xe000ed00?0xe000ed3f system control block 0xe000ed90?0xe000edb8 memory protection unit 0xe000ef00?0xe000ef03 nested vectored interrupt controller 0xe000ef30?0xe000ef44 floating-point unit
229 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.8 nested vectored inte rrupt contro ller (nvic) this section describes the nvic and the registers it uses. the nvic supports: ? up to 41 interrupts ? a programmable priority level of 0?15 for each interrupt. a higher level corresponds to a lower priority, so level 0 is the highest interrupt priority. ? level detection of interrupt signals ? dynamic reprioritization of interrupts ? grouping of priority values into group priority and subpriority fields ? interrupt tail-chaining ? an external non-maskable interrupt (nmi) the processor automatically stacks its state on exception entry and unstacks this state on exception exit, with no instruction overhead. this provid es low latency ex ception handling. 12.8.1 level-sensitive interrupts the processor supports level- sensitive interrupts. a leve l-sensitive interrupt is hel d asserted until the peripheral deasserts the interrupt signal. typically, this happens bec ause the isr accesses the perip heral, causing it to clear the interrupt request. when the processor enters the isr, it automatically removes the pending state from the interrupt (see ?hardware and software control of interrupts? ). for a level-sensitive interrupt, if the signal is not deasserted before the processor returns from the isr, t he interrupt becomes pending again, and the processor must execute its isr again. this means that the peripheral can hold the interrup t signal asserted until it no longer requires servicing. 12.8.1.1 hardware and software control of interrupts the cortex-m4 latches all in terrupts. a peripheral interrupt becomes pending for one of the following reasons: ? the nvic detects that the interrupt signal is high and the interrupt is not active ? the nvic detects a rising edge on the interrupt signal ? a software writes to the corresponding interrupt set-pending register bit, see ?interrupt set-pending registers? , or to the nvic_stir to make an interrupt pending, see ?software trigger interrupt register? . a pending interrupt remains pend ing until one of the following: ? the processor enters the isr for the interrupt. this changes the state of the interrupt from pending to active. then: ? for a level-sensitive interrupt, when the proces sor returns from the isr, the nvic samples the interrupt signal. if the signal is asserted, the state of the interrupt changes to pending, which might cause the processor to immediately re-enter the isr. otherwise, the state of the interrupt changes to inactive. ? software writes to the corresponding interrupt clear-pending register bit. for a level-sensitive interrupt, if the interrupt signal is still asserted, the state of the interrupt does not change. otherwise, the state of th e interrupt changes to inactive.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 230 12.8.2 nvic design hints and tips ensure that the software uses correctly aligned register accesses. the processor does not support unaligned accesses to nvic registers. see the individual r egister descriptions for the supported access sizes. a interrupt can enter a pending state even if it is disabled. disabling an inte rrupt only prevents the processor from taking that interrupt. before programming scb_vtor to relocate the vector table, ensure that the vector table entries of the new vector table are set up for fault handlers, nmi and all enabled exception like interrupts. for more information, see the ?vector table offset register? . 12.8.2.1 nvic programming hints the software uses the cpsie i and cpsid i instructions to enable and disable the interrupts. the cmsis provides the following intrinsic functi ons for these instructions: void __disable_irq(void) // disable interrupts void __enable_irq(void) // enable interrupts in addition, the cmsis provides a number of functions for nvic control, including: the input parameter irqn is the irq number. for more information about these functions, see the cmsis documentation. to improve software efficiency, the cmsis simplifie s the nvic register presentation. in the cmsis: ? the set-enable, clear-enable, set-pending, clear-pending and active bit registers map to arrays of 32-bit integers, so that: ? the array iser[0] to iser[1] corres ponds to the registers iser0?iser1 ? the array icer[0] to ic er[1] corresponds to the registers icer0?icer1 ? the array ispr[0] to ispr[1] corres ponds to the registers ispr0?ispr1 ? the array icpr[0] to ic pr[1] corresponds to the registers icpr0?icpr1 ? the array iabr[0] to iabr[1] corres ponds to the registers iabr0?iabr1 ? the interrupt priority registers (ipr0?ipr10) provide an 8-bit priority field for each interrupt and each register holds four priority fields. table 12-30. cmsis functions for nvic control cmsis interrupt control function description void nvic_setprioritygrouping(uint32_t pr iority_grouping) set the priority grouping void nvic_enableirq(ir qn_t irqn) enable irqn void nvic_disableirq(irqn_t irqn) disable irqn uint32_t nvic_getpendingirq (irqn_t irqn) ret urn true (irq-number) if irqn is pending void nvic_setpendingirq (irqn_t irqn) set irqn pending void nvic_clearpendingirq (irqn_t irqn) clear irqn pending status uint32_t nvic_getactive (irqn_t irqn) return the irq number of the active interrupt void nvic_setpriority (i rqn_t irqn, uint32_t priority) set priority for irqn uint32_t nvic_getpriority (irq n_t irqn) read priority of irqn void nvic_systemreset (void) reset the system
231 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the cmsis provides thread-safe code that gives atomic access to the interrupt priority registers. table 12-31 shows how the interrupts, or irq numbers, map onto the interrupt registers and corresponding cmsis variables that have one bit per interrupt. note: 1. each array element corresponds to a single nvic re gister, for example the icer[0] element corresponds to the icer0. table 12-31. mapping of interrup ts to the interrupt variables interrupts cmsis array elements (1) set-enable clear-enable set-pending clear-pending active bit 0?31 iser[0] icer[0] ispr[0] icpr[0] iabr[0] 32?41 iser[1] icer[1] ispr[1] icpr[1] iabr[1]
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 232 12.8.3 nested vectored interrupt controller (nvic) user interface table 12-32. nested vectored interrupt controller (nvic) register mapping offset register name access reset 0xe000e100 interrupt set-enable register 0 nvic_iser0 read/write 0x00000000 ... ... ... ... ... 0xe000e11c interrupt set-enable register 7 nvic_iser7 read/write 0x00000000 0xe000e180 interrupt clear-enable register 0 nvic_icer0 read/write 0x00000000 ... ... ... ... ... 0xe000e19c interrupt clear-enable register 7 nvic_icer7 read/write 0x00000000 0xe000e200 interrupt set-pending regist er 0 nvic_ispr0 read/write 0x00000000 ... ... ... ... ... 0xe000e21c interrupt set-pending regist er 7 nvic_ispr7 read/write 0x00000000 0xe000e280 interrupt clear-pending regi ster 0 nvic_icpr0 read/write 0x00000000 ... ... ... ... ... 0xe000e29c interrupt clear-pending regi ster 7 nvic_icpr7 read/write 0x00000000 0xe000e300 interrupt active bit regi ster 0 nvic_iabr0 read/write 0x00000000 ... ... ... ... ... 0xe000e31c interrupt active bit regi ster 7 nvic_iabr7 read/write 0x00000000 0xe000e400 interrupt priority regi ster 0 nvic_ipr0 read/write 0x00000000 ... ... ... ... ... 26 interrupt priority register 10 nvic_ipr10 read/write 0x00000000 0xe000ef00 software trigger interrupt register nvic_stir write-only 0x00000000
233 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.8.3.1 interrupt set-enable registers name: nvic_iserx [x=0..7] access: read/write reset: 0x000000000 these registers enable interrupts and show which interrupts are enabled. ? setena: interrupt set-enable write: 0: no effect. 1: enables the interrupt. read: 0: interrupt disabled. 1: interrupt enabled. notes: 1. if a pending interrupt is enabled, the nvic activates the interrupt based on its priority. 2. if an interrupt is not enabled, asserti ng its interrupt signal changes the interrupt state to pending, the nvic never activat es the interrupt, regardless of its priority. 31 30 29 28 27 26 25 24 setena 23 22 21 20 19 18 17 16 setena 15 14 13 12 11 10 9 8 setena 76543210 setena
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 234 12.8.3.2 interrupt clear-enable registers name: nvic_icerx [x=0..7] access: read/write reset: 0x000000000 these registers disable interrupts, and show which interrupts are enabled. ? clrena: interrupt clear-enable write: 0: no effect. 1: disables the interrupt. read: 0: interrupt disabled. 1: interrupt enabled. 31 30 29 28 27 26 25 24 clrena 23 22 21 20 19 18 17 16 clrena 15 14 13 12 11 10 9 8 clrena 76543210 clrena
235 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.8.3.3 interrupt set-pending registers name: nvic_isprx [x=0..7] access: read/write reset: 0x000000000 these registers force interrupts into the pending state, and show which interrupts are pending. ? setpend: interrupt set-pending write: 0: no effect. 1: changes the interrupt state to pending. read: 0: interrupt is not pending. 1: interrupt is pending. notes: 1. writing a 1 to an ispr bit corresponding to an interrupt that is pending has no effect. 2. writing a 1 to an ispr bit corresponding to a disabled interrupt sets the state of that interrupt to pending. 31 30 29 28 27 26 25 24 setpend 23 22 21 20 19 18 17 16 setpend 15 14 13 12 11 10 9 8 setpend 76543210 setpend
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 236 12.8.3.4 interrupt clear-pending registers name: nvic_icprx [x=0..7] access: read/write reset: 0x000000000 these registers remove the pending state from in terrupts, and show which interrupts are pending. ? clrpend: interrupt clear-pending write: 0: no effect. 1: removes the pending state from an interrupt. read: 0: interrupt is not pending. 1: interrupt is pending. note: writing a 1 to an icpr bit does not affect the active state of the corresponding interrupt. 31 30 29 28 27 26 25 24 clrpend 23 22 21 20 19 18 17 16 clrpend 15 14 13 12 11 10 9 8 clrpend 76543210 clrpend
237 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.8.3.5 interrupt active bit registers name: nvic_iabrx [x=0..7] access: read/write reset: 0x000000000 these registers indicate which interrupts are active. ? active: interrupt active flags 0: interrupt is not active. 1: interrupt is active. note: a bit reads as one if the status of the corresponding interrupt is active, or active and pending. 31 30 29 28 27 26 25 24 active 23 22 21 20 19 18 17 16 active 15 14 13 12 11 10 9 8 active 76543210 active
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 238 12.8.3.6 interrupt priority registers name: nvic_iprx [x=0..10] access: read/write reset: 0x000000000 the nvic_ipr0?nvic_ipr10 registers provide a 8-bit priority field for each interrup t. these registers are byte-accessible. each register holds four priority fields that map up to four elements in the cmsis interrupt pr iority array ip[0] to ip[40]. ? pri3: priority (4m+3) priority, byte offset 3, refe rs to register bits [31:24]. ? pri2: priority (4m+2) priority, byte offset 2, refe rs to register bits [23:16]. ? pri1: priority (4m+1) priority, byte offset 1, refers to register bits [15:8]. ? pri0: priority (4m) priority, byte offset 0, refers to register bits [7:0]. notes: 1. each priority field holds a priority value, 0?15. the lower the value, the greater the priority of the corresponding in terrupt. the processor implements only bits[7:4] of each field; bits[3:0] read as zero and ignore writes. 2. for more information about the ip[0] to ip[40] interrupt priori ty array, that provides the software view of the interrupt priorities, see table 12-30, ?cmsis functions for nvic control? . 3. the corresponding ipr number n is given by n = m div 4. 4. the byte offset of the required pr iority field in this register is m mod 4. 31 30 29 28 27 26 25 24 pri3 23 22 21 20 19 18 17 16 pri2 15 14 13 12 11 10 9 8 pri1 76543210 pri0
239 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.8.3.7 software trigger interrupt register name: nvic_stir access: write-only reset: 0x000000000 write to this register to genera te an interrupt from the software. ? intid: interrupt id interrupt id of the interrupt to trigger, in the range 0?239. for example, a value of 0x03 specifies in terrupt irq3. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????i n t i d 76543210 intid
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 240 12.9 system control block (scb) the system control block (scb) prov ides system implementation informati on, and system control. this includes configuration, control, and repor ting of the system exceptions. ensure that the software uses aligned accesses of the correct size to acce ss the system control block registers: ? except for the scb_cfsr and scb_shpr1?scb_shpr3 registers, it must us e aligned word accesses ? for the scb_cfsr and scb_ shpr1?scb_shpr3 registers, it can use byte or aligned halfword or word accesses. the processor does not support unaligned accesses to system control block registers. in a fault handler, to determine the true faulting address: 1. read and save the mmfar or scb_bfar value. 2. read the mmarvalid bit in the mmfsr subregister, or the bfarvalid bit in the bfsr subregister. the scb_mmfar or scb_bfar address is valid only if this bit is 1. the software must follow this sequence because anothe r higher priority exception might change the scb_mmfar or scb_bfar value. for example, if a higher priority handler preempts the current fault handler, the other fault might change the scb_mm far or scb_bfar value.
241 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.9.1 system control block (scb) user interface notes: 1. see the register description for more information. 2. this register contains the subregisters: ?mmfsr: memory management fault status subregister? (0xe000ed28 - 8 bits), ?bfsr: bus fault status subregister? (0xe000ed29 - 8 bits), ?ufsr: usage fault status subregister? (0xe000ed2a - 16 bits). table 12-33. system control block (scb) register mapping offset register name access reset 0xe000e008 auxiliary control register scb_actlr read/write 0x00000000 0xe000ed00 cpuid base register scb_cpuid read-only 0x410fc240 0xe000ed04 interrupt control and state register scb_icsr read/write (1) 0x00000000 0xe000ed08 vector table offset register scb_vtor read/write 0x00000000 0xe000ed0c application interrupt and reset c ontrol register scb_aircr read/write 0xfa050000 0xe000ed10 system control register scb_scr read/write 0x00000000 0xe000ed14 configuration and control register scb_ccr read/write 0x00000200 0xe000ed18 system handler priority re gister 1 scb_shpr1 read/write 0x00000000 0xe000ed1c system handler priority re gister 2 scb_shpr2 read/write 0x00000000 0xe000ed20 system handler priority re gister 3 scb_shpr3 read/write 0x00000000 0xe000ed24 system handler control and stat e register scb_shcsr read/write 0x00000000 0xe000ed28 configurable fault status register scb_cfsr (2) read/write 0x00000000 0xe000ed2c hardfault status register scb_hfsr read/write 0x00000000 0xe000ed34 memmanage fault address register scb_mmfar read/write unknown 0xe000ed38 busfault address register scb_bfar read/write unknown 0xe000ed3c auxiliary fault status r egister scb_afsr read/write 0x00000000
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 242 12.9.1.1 auxiliary control register name: scb_actlr access: read/write the scb_actlr provides disable bits for the following processor functions: ? it folding ? write buffer use for accesses to the default memory map ? interruption of multi-cycle instructions. by default, this register is set to pr ovide optimum performance from the cortex -m4 processor, and does not normally require modification. ? disoofp: disable out of order floating point disables floating point instructions that complete out of order with respect to integer instructions. ? disfpca: disable fpca disables an automatic update of control.fpca. ? disfold: disable folding when set to 1, disables the it folding. note: in some situations, the processor can start executing the fi rst instruction in an it block while it is still executing the it instruction. this behavior is called it folding, and it improves the performa nce. however, it folding can cause jitter in looping. if a task must avoid jitter, set the disfold bi t to 1 before executing the task, to disable the it folding. ? disdefwbuf: disable default write buffer when set to 1, it disables the write buffer use during defaul t memory map accesses. this causes busfault to be precise but decreases the performance, as any store to memory mu st complete before the proc essor can execute the next instruction. this bit only affects write buffers implemented in the cortex-m4 processor. ? dismcycint: disable multiple cycle interruption when set to 1, it disables the interruption of load multiple and store multiple instructions . this increases the interrupt latency of the processor, as any ldm or stm must complete before the processor can stack the current state and enter the interrupt handler. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? disoofp disfpca 76543210 ? disfold disdefwbuf dismcycint
243 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.9.1.2 cpuid base register name: scb_cpuid access: read/write the scb_cpuid register contains the processor part number, version, and implementation information. ? implementer: im plementer code 0x41: arm. ? variant: variant number it is the r value in the rnpn product revision identifier: 0x0: revision 0. ? constant: reads as 0xf reads as 0xf. ? partno: part number of the processor 0xc24 = cortex-m4. ? revision: revision number it is the p value in the rnpn product revision identifier: 0x0: patch 0. 31 30 29 28 27 26 25 24 implementer 23 22 21 20 19 18 17 16 variant constant 15 14 13 12 11 10 9 8 partno 76543210 partno revision
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 244 12.9.1.3 interrupt control and state register name: scb_icsr access: read/write the scb_icsr provides a set-pending bit for the non-maska ble interrupt (nmi) exception, and set-pending and clear- pending bits for the pendsv and systick exceptions. it indicates: ? the exception number of the exception being processed, and whether there are preempted active exceptions, ? the exception number of the highest priority pending exception, and whether any interrupts are pending. ? nmipendset: nmi set-pending write: pendsv set-pending bit. write: 0: no effect. 1: changes nmi except ion state to pending. read: 0: nmi exception is not pending. 1: nmi exception is pending. as nmi is the highest-priority exception, the processor normally enters the nmi except ion handler as soon as it registers a write of 1 to this bit. entering the handler clears this bit to 0. a read of this bit by the nmi exception handler returns 1 on ly if the nmi signal is reasserted while the processor is executing that handler. ? pendsvset: pendsv set-pending write: 0: no effect. 1: changes pendsv exception state to pending. read: 0: pendsv exception is not pending. 1: pendsv exception is pending. writing a 1 to this bit is the only way to set the pendsv exception state to pending. ? pendsvclr: pend sv clear-pending 31 30 29 28 27 26 25 24 nmipendset ? pendsvset pendsvclr pendstset pendstclr ? 23 22 21 20 19 18 17 16 ? isrpending vectpending 15 14 13 12 11 10 9 8 vectpending rettobase ? vectactive 76543210 vectactive
245 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 write: 0: no effect. 1: removes the pending state from the pendsv exception. ? pendstset: systick e xception set-pending write: 0: no effect. 1: changes systick exception state to pending. read: 0: systick exception is not pending. 1: systick exception is pending. ? pendstclr: systick exception clear-pending write: 0: no effect. 1: removes the pending state from the systick exception. this bit is write-only. on a regi ster read, its value is unknown. ? isrpending: interrupt pending fl ag (excluding nmi and faults) 0: interrupt not pending. 1: interrupt pending. ? vectpending: exception number of the highest priority pending enabled exception 0: no pending exceptions. nonzero: the exception number of the hi ghest priority pending enabled exception. the value indicated by this field include s the effect of the basepri and faultmask registers, but not any effect of the primask register. ? rettobase: preempted active exceptions present or not 0: there are preempted active exceptions to execute. 1: there are no active exceptions, or the currentl y-executing exception is th e only active exception. ? vectactive: active exce ption number contained 0: thread mode. nonzero: the exception number of the currently active exce ption. the value is the same as ipsr bits [8:0]. see ?interrupt program status register? . subtract 16 from this value to obtain the irq number required to index into the interrupt clear-enable, set-enable, clear- pending, set-pending, or priority registers, see ?interrupt program status register? . note: when the user writes to the scb_icsr, the effect is unpredictable if: - writing a 1 to the pendsvset bit and writing a 1 to the pe ndsvclr bit - writing a 1 to the pendstset bit and writing a 1 to the pendstclr bit.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 246 12.9.1.4 vector table offset register name: scb_vtor access: read/write the scb_vtor indicates the offset of the vector table base address from memory address 0x00000000. ? tbloff: vector table base offset it contains bits [29:7] of th e offset of the table base from the bottom of the memory map. bit [29] determines whether the vector table is in the code or sram memory region: 0: code. 1: sram. it is sometimes called the tblbase bit. note: when setting tbloff, the offset must be aligned to the number of exception entries in the ve ctor table. configure the next statement to give the information required for your implementa tion; the statement reminds the user of how to determine the alignment requirement. the minimum alignment is 32 words, enoug h for up to 16 interrupts. for more interrupts, adjust the alignment by rounding up to the next power of two. for example, if 21 interrupts are required, the alignment must be on a 64-wo rd boundary because the required table size is 37 words, and the next power of two is 64. table alignment requirements mean that bits [6:0] of the table o ffset are always zero. 31 30 29 28 27 26 25 24 tbloff 23 22 21 20 19 18 17 16 tbloff 15 14 13 12 11 10 9 8 tbloff 76543210 tbloff ?
247 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.9.1.5 application interrupt and reset control register name: scb_aircr access: read/write the scb_aircr provides priority grouping control for the ex ception model, endian status for data accesses, and reset control of the system. to write to this register, write 0x5f a to the vectkey field, other wise the processo r ignores the write. ? vectkeystat: register key read: reads as 0xfa05. ? vectkey: register key write: writes 0x5fa to vectkey, othe rwise the writ e is ignored. ? endianness: data endianness 0: little-endian. 1: big-endian. ? prigroup: interrupt priority grouping this field determines the split of group priority from subprior ity. it shows the position of t he binary point that splits the p ri_ n fields in the interrupt priori ty registers into separate group priority and subpriority fields. the table below shows how the prigroup value controls this split. 31 30 29 28 27 26 25 24 vectkeystat/vectkey 23 22 21 20 19 18 17 16 vectkeystat/vectkey 15 14 13 12 11 10 9 8 endianness ? prigroup 76543210 ? sysresetreq vectclracti ve vectreset prigroup interrupt priority level value, pri_ n [7:0] number of binary point (1) group priority bits subpriority bits group priorities subpriorities 0b000 bxxxxxxx.y [7:1] none 128 2 0b001 bxxxxxx.yy [7:2] [4:0] 64 4 0b010 bxxxxx.yyy [7:3] [4:0] 32 8 0b011 bxxxx.yyyy [7:4] [4:0] 16 16 0b100 bxxx.yyyyy [7:5] [4:0] 8 32 0b101 bxx.yyyyyy [7:6] [5:0] 4 64 0b110 bx.yyyyyyy [7] [6:0] 2 128
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 248 note: 1. pri_n[7:0] field showing the binary point. x denotes a gr oup priority field bit, and y denotes a subpriority field bit. determining preemption of an exception uses only the group priority field. ? sysresetreq: system reset request 0: no system reset request. 1: asserts a signal to the oute r system that requests a reset. this is intended to force a large system reset of all major components except for debug. this bit reads as 0. ? vectclractive: reserved for debug use this bit reads as 0. when writing to the register, write a 0 to this bit, otherwise the behavior is unpredictable. ? vectreset: reserved for debug use this bit reads as 0. when writing to the register, write a 0 to this bit, otherwise the behavior is unpredictable. 0b111 b.yyyyyyy none [7:0] 1 256 prigroup interrupt priority level value, pri_ n [7:0] number of binary point (1) group priority bits subpriority bits group priorities subpriorities
249 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.9.1.6 system control register name: scb_scr access: read/write ? sevonpend: send event on pending bit 0: only enabled interrupts or events can wake up the processor; disabled interrupts are excluded. 1: enabled events and all interrupts, including disabled interrupts, can wake up the processor. when an event or an interrupt enters the pending state, the event signal wakes up the processor from wfe. if the proces- sor is not waiting for an event, the event is registered and affects the next wfe. the processor also wakes up on execution of an sev instruction or an external event. ? sleepdeep: sleep or deep sleep controls whether the proces sor uses sleep or deep sleep as its low power mode: 0: sleep. 1: deep sleep. ? sleeponexit: sleep-on-exit indicates sleep-on-exit when returning from the handler mode to the thread mode: 0: do not sleep when returning to thread mode. 1: enter sleep, or deep sleep, on return from an isr. setting this bit to 1 enables an interrupt-driven application to avoid returning to an empty main application. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? sevonpend ? sleepdeep sleeponexit ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 250 12.9.1.7 configuration and control register name: scb_ccr access: read/write the scb_ccr controls the entry to the thread mode and enable s the handlers for nmi, hard fault and faults escalated by faultmask to ignore busfaul ts. it also enables the divisi on by zero and unaligned access trapping, and the access to the nvic_stir by unprivileged software (see ?software trigger interrupt register? ). ? stkalign: stack alignment indicates the stack alignment on exception entry: 0: 4-byte aligned. 1: 8-byte aligned. on exception entry, the processor uses bit [9] of the stacke d psr to indicate the stack a lignment. on return from the exception, it uses this stacked bit to restore the correct stack alignment. ? bfhfnmign: bus faults ignored enables handlers with priority -1 or -2 to ignore data bus faul ts caused by load and store instructions. this applies to the hard fault and faultmask escalated handlers: 0: data bus faults caused by load and store instructions cause a lock-up. 1: handlers running at priority -1 and -2 ignore data bus faults caused by load and store instructions. set this bit to 1 only when the handler and its data are in absolutely safe memory. the normal use of this bit is to probe sys- tem devices and bridges to detect control path problems and fix them. ? div_0_trp: division by zero trap enables faulting or halting when the processor execut es an sdiv or udiv instruction with a divisor of 0: 0: do not trap divide by 0. 1: trap divide by 0. when this bit is set to 0, a divide by zero returns a quotient of 0. ? unalign_trp: unaligned access trap enables unaligned access traps: 0: do not trap unaligned halfword and word accesses. 1: trap unaligned halfword and word accesses. if this bit is set to 1, an unalig ned access generates a usage fault. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? stkalign bfhfnmign 76543210 ? div_0_trp unalign_trp ? usersetmpe nd nonbasethr dena
251 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 unaligned ldm, stm, ldrd, and strd in structions always fault irrespective of whether unalign_trp is set to 1. ? usersetmpend: unpriv ileged software access enables unprivileged software access to the nvic_stir, see ?software trigger interrupt register? : 0: disable. 1: enable. ? nonbasethrdena: thread mode enable indicates how the processor enters thread mode: 0: the processor can enter the thread mode only when no exception is active. 1: the processor can enter the thread mode from any level under the control of an exc_return value, see ?exception return? .
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 252 12.9.1.8 system handler priority registers the scb_shpr1?scb_shpr3 registers set the priority level, 0 to 15 of the exception handlers that have configurable pri- ority. they are byte-accessible. the system fault handlers and the priority field and regi ster for each handler are: each pri_n field is 8 bits wide, but the processor implements only bits [7:4] of each field, and bits [3:0] read as zero and ignore writes. table 12-34. system fault handler priority fields handler field register description memory management fault (memmanage) pri_4 system handler priority register 1 bus fault (busfault) pri_5 usage fault (usagefault) pri_6 svcall pri_11 system handler priority register 2 pendsv pri_14 system handler priority register 3 systick pri_15
253 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.9.1.9 system handler priority register 1 name: scb_shpr1 access: read/write ? pri_6: priority priority of system handler 6, usagefault. ? pri_5: priority priority of system handler 5, busfault. ? pri_4: priority priority of system handler 4, memmanage. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 pri_6 15 14 13 12 11 10 9 8 pri_5 76543210 pri_4
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 254 12.9.1.10system handler priority register 2 name: scb_shpr2 access: read/write ? pri_11: priority priority of system handler 11, svcall. 31 30 29 28 27 26 25 24 pri_11 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ?
255 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.9.1.11system handler priority register 3 name: scb_shpr3 access: read/write ? pri_15: priority priority of system hand ler 15, systick exception. ? pri_14: priority priority of system handler 14, pendsv. 31 30 29 28 27 26 25 24 pri_15 23 22 21 20 19 18 17 16 pri_14 15 14 13 12 11 10 9 8 ? 76543210 ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 256 12.9.1.12system handler control and state register name: scb_shcsr access: read/write the shcsr enables the system handlers, and indicates the pending status of the bus faul t, memory management fault, and svc exceptions; it also indicates t he active status of the system handlers. ? usgfaultena: usage fault enable 0: disables the exception. 1: enables the exception. ? busfaultena: bus fault enable 0: disables the exception. 1: enables the exception. ? memfaultena: memory management fault enable 0: disables the exception. 1: enables the exception. ? svcallpended: svc call pending read: 0: the exception is not pending. 1: the exception is pending. note: the user can write to these bits to change the pending status of the exceptions. ? busfaultpended: bus fault exception pending read: 0: the exception is not pending. 1: the exception is pending. note: the user can write to these bits to change the pending status of the exceptions. ? memfaultpended: memory management fault exception pending read: 0: the exception is not pending. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? usgfaultena busfaultena memfaultena 15 14 13 12 11 10 9 8 svcallpende d busfaultpen ded memfaultpen ded usgfaultpen ded systickact pendsvact ? monitoract 76543210 svcallact ? usgfaultact ? busfaultact memfaultact
257 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1: the exception is pending. note: the user can write to these bits to change the pending status of the exceptions. ? usgfaultpended: usage fault exception pending read: 0: the exception is not pending. 1: the exception is pending. note: the user can write to these bits to change the pending status of the exceptions. ? systickact: systick exception active read: 0: the exception is not active. 1: the exception is active. note: the user can write to these bits to c hange the active status of the exceptions. - caution: a software that changes the value of an active bit in this register without a correct adjustment to the stacked cont ent can cause the processor to generate a fault exception. ensure that the software writing to this register retains and subsequent ly restores the current active status. - caution: after enabling the system handlers, to change the val ue of a bit in this register, the user must use a read-modify-w rite procedure to ensure that only the required bit is changed. ? pendsvact: pendsv exception active 0: the exception is not active. 1: the exception is active. ? monitoract: debug monitor active 0: debug monitor is not active. 1: debug monitor is active. ? svcallact: svc call active 0: svc call is not active. 1: svc call is active. ? usgfaultact: usage fault exception active 0: usage fault except ion is not active. 1: usage fault exce ption is active. ? busfaultact: bus fault exception active 0: bus fault exception is not active. 1: bus fault exception is active. ? memfaultact: memory management fault exception active 0: memory management fault exception is not active. 1: memory management fault exception is active. if the user disables a system handler and the corresponding fault occurs, the proc essor treats the fault as a hard fault. the user can write to this register to change the pending or ac tive status of system exceptions . an os kernel can write to the active bits to perform a context swit ch that changes the current exception type.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 258 12.9.1.13configurable fault status register name: scb_cfsr access: read/write ? iaccviol: instruction access violation flag this is part of ?mmfsr: memory management fault status subregister? . 0: no instruction access violation fault. 1: the processor attempted an instruction fetch fr om a location that does not permit execution. this fault occurs on any access to an xn regi on, even when the mpu is disabled or not present. when this bit is 1, the pc value stacked for the exception re turn points to the faulting instruction. the processor has not written a fault address to the scb_mmfar. ? daccviol: data access violation flag this is part of ?mmfsr: memory management fault status subregister? . 0: no data access violation fault. 1: the processor attempted a load or store at a location that does not permit the operation. when this bit is 1, the pc value stacked for the exception return points to the faul ting instruction. the processor has loaded the scb_mmfar with the address of the attempted access. ? munstkerr: memory manager fault on unstacking for a return from exception this is part of ?mmfsr: memory management fault status subregister? . 0: no unstacking fault. 1: unstack for an exception return has caused one or more access violations. this fault is chained to the handler. this means that when this bit is 1, the original return stack is still present. the proce s- sor has not adjusted the sp from the failing return, and has not per formed a new save. the pr ocessor has not written a fault address to the scb_mmfar. ? mstkerr: memory manager fault on stacking for exception entry this is part of ?mmfsr: memory management fault status subregister? . 0: no stacking fault. 1: stacking for an exception entry has caused one or more access violations. when this bit is 1, the sp is still adjusted but the values in the context area on the stack mi ght be incorrect. the processor has not written a fault address to scb_mmfar. ? mlsperr: memmanage during lazy state preservation 31 30 29 28 27 26 25 24 ? divbyzero unaligned 23 22 21 20 19 18 17 16 ? nocp invpc invstate undefinstr 15 14 13 12 11 10 9 8 bfarvalid ? lsperr stkerr unstkerr impreciserr preciserr ibuserr 76543210 mmarvalid ? mlsperr mstkerr munstkerr ? daccviol iaccviol
259 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 this is part of ?mmfsr: memory management fault status subregister? . 0: no memmanage fault occurred during the floating-point lazy state preservation. 1: a memmanage fault occurred during the fl oating-point lazy state preservation. ? mmarvalid: memory management fault address register (scb_mmfar) valid flag this is part of ?mmfsr: memory management fault status subregister? . 0: the value in scb_mmfar is not a valid fault address. 1: scb_mmfar holds a valid fault address. if a memory management fault occurs and is escalated to a hard fault because of priority, the hard fault handler must set this bit to 0. this prevents problems on return to a stacked active memory management fault handler whose scb_mmfar value has been overwritten. ? ibuserr: instruction bus error this is part of ?bfsr: bus fault status subregister? . 0: no instruction bus error. 1: instruction bus error. the processor detects the instruction bus error on prefetching an instruction, but it sets the ibuserr flag to 1 only if it attempts to issue the faulting instruction. when the processor sets this bit to 1, it does not write a fault address to the bfar. ? preciserr: precise data bus error this is part of ?bfsr: bus fault status subregister? . 0: no precise data bus error. 1: a data bus error has occurred, and the pc value stacked for the exception return points to the instruction that caused the fault. when the processor sets this bit to 1, it writes the faulting address to the scb_bfar. ? impreciserr: imprecise data bus error this is part of ?bfsr: bus fault status subregister? . 0: no imprecise data bus error. 1: a data bus error has occurred, but the return address in the stack frame is not related to the instruction that caused the error. when the processor sets this bit to 1, it d oes not write a fault address to the scb_bfar. this is an asynchronous fault. therefore, if it is detected wh en the priority of the current process is higher than the bus fau lt priority, the bus fault becomes pending and becomes active only when the processor returns from all higher priority pro- cesses. if a precise fault occurs before the processor enters the handler for the imprecise bus fault, the handler detects that both this bit and one of the prec ise fault status bits are set to 1. ? unstkerr: bus fault on unstacking for a return from exception this is part of ?bfsr: bus fault status subregister? . 0: no unstacking fault. 1: unstack for an exception return has caused one or more bus faults.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 260 this fault is chained to the handler. this means that when the processor sets this bit to 1, the original return stack is still present. the processor d oes not adjust the sp from the failing return, d oes not performed a new save, and does not write a fault address to the bfar. ? stkerr: bus fault on stacking for exception entry this is part of ?bfsr: bus fault status subregister? . 0: no stacking fault. 1: stacking for an exception entry has caused one or more bus faults. when the processor sets this bit to 1, the sp is still adjusted but the values in the context area on the stack might be incor- rect. the processor does not write a fault address to the scb_bfar. ? lsperr: bus error during lazy fl oating-point stat e preservation this is part of ?bfsr: bus fault status subregister? . 0: no bus fault occurred during fl oating-point lazy state preservation 1: a bus fault occurred during floa ting-point lazy state preservation. ? bfarvalid: bus fault address register (bfar) valid flag this is part of ?bfsr: bus fault status subregister? . 0: the value in scb_bfar is not a valid fault address. 1: scb_bfar holds a valid fault address. the processor sets this bit to 1 after a bus fault where the addr ess is known. other faults can set this bit to 0, such as a memory management fault occurring later. if a bus fault occurs and is escalated to a hard fault because of priority, the hard fault handler must set this bit to 0. this prevents problems if returning to a stacked active bus fault handler whose scb_bfar value has been overwritten. ? undefinstr: undefined instruction usage fault this is part of ?ufsr: usage fault status subregister? . 0: no undefined instruction usage fault. 1: the processor has attempted to execute an undefined instruction. when this bit is set to 1, the pc value stacked for t he exception return points to the undefined instruction. an undefined instruction is an instru ction that the processor cannot decode. ? invstate: invalid state usage fault this is part of ?ufsr: usage fault status subregister? . 0: no invalid state usage fault. 1: the processor has attempted to execute an instru ction that makes illegal use of the epsr. when this bit is set to 1, the pc value stacked for the exception retu rn points to the instructi on that attempted the illegal use of the epsr. this bit is not set to 1 if an undefined instruction uses the epsr. ? invpc: invalid pc load usage fault this is part of ?ufsr: usage fault status subregister? . it is caused by an invalid pc load by exc_return: 0: no invalid pc load usage fault.
261 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1: the processor has attempted an illegal lo ad of exc_return to the pc, as a result of an invalid cont ext, or an invalid exc_return value. when this bit is set to 1, the pc value stacked for the exception return points to the instruction that tried to perform the il le- gal load of the pc. ? nocp: no coprocessor usage fault this is part of ?ufsr: usage fault status subregister? . the processor does not sup port coprocessor instructions: 0: no usage fault caused by attempting to access a coprocessor. 1: the processor has attempted to access a coprocessor. ? unaligned: unaligned access usage fault this is part of ?ufsr: usage fault status subregister? . 0: no unaligned access fault, or unaligned access trapping not enabled. 1: the processor has made an unaligned memory access. enable trapping of unaligned accesses by setting the unalign_trp bit in the scb_ccr to 1. see ?configuration and control register? . unaligned ldm, stm, ldrd, and strd instructions always fault irrespective of the setting of unalign_trp. ? divbyzero: divide by zero usage fault this is part of ?ufsr: usage fault status subregister? . 0: no divide by zero fault, or divide by zero trapping not enabled. 1: the processor has executed an sdiv or udiv instruction wi th a divisor of 0. when the processor sets this bit to 1, th e pc value stacked for the exception return points to the instruction that performed the divide by zero. enable trapping of divide by zero by setting the div_0_trp bit in the scb_ccr to 1. see ?configura- tion and control register? .
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 262 12.9.1.14configurable fault status register (byte access) name: scb_cfsr (byte) access: read/write ? mmfsr: memory management fault status subregister the flags in the mmfsr subregister indicate the cause of memory access faults. see bitfield [7..0] description in section 12.9.1.13 . ? bfsr: bus fault status subregister the flags in the bfsr subregister indicate the cause of a bus access fault. see bitfield [14..8] description in section 12.9.1.13 . ? ufsr: usage fault status subregister the flags in the ufsr subregister indicate the cause of a usage fault. see bitfield [31..15] description in section 12.9.1.13 . note: the ufsr bits are sticky. this means that as one or more f ault occurs, the associated bits are set to 1. a bit that is set to 1 is cleared to 0 only by wrting a 1 to that bit, or by a reset. the scb_cfsr indicates the cause of a memory management faul t, bus fault, or usage fault. it is byte accessible. the user can access the scb_cfsr or its subregisters as follows: ? access complete scb_cfsr with a word access to 0xe000ed28 ? access mmfsr with a byte access to 0xe000ed28 ? access mmfsr and bfsr with a halfword access to 0xe000ed28 ? access bfsr with a byte access to 0xe000ed29 ? access ufsr with a halfword access to 0xe000ed2a. 31 30 29 28 27 26 25 24 ufsr 23 22 21 20 19 18 17 16 ufsr 15 14 13 12 11 10 9 8 bfsr 76543210 mmfsr
263 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.9.1.15hard fault status register name: scb_hfsr access: read/write the scb_hfsr gives information about events that activate the hard fault handler. th is register is read, write to clear. this means that bits in the register read normally, but wrting a 1 to any bit clears that bit to 0. ? debugevt: reserved for debug use when writing to the register, write a 0 to th is bit, otherwise the behavior is unpredictable. ? forced: forced hard fault it indicates a forced hard fault, generated by escalation of a f ault with configurable priority that cannot be handles, either because of priority or because it is disabled: 0: no forced hard fault. 1: forced hard fault. when this bit is set to 1, the hard faul t handler must read the other fault status registers to find the cause of the fault. ? vecttbl: bus fault on a vector table it indicates a bus fault on a vector table read during an exception processing: 0: no bus fault on vector table read. 1: bus fault on vector table read. this error is always handled by the hard fault handler. when this bit is set to 1, the pc value stacked for the except ion return points to the instruction that was preempted by the exception. note: the hfsr bits are sticky. this means that, as one or more fa ult occurs, the associated bits are set to 1. a bit that is se t to 1 is cleared to 0 only by wrting a 1 to that bit, or by a reset. 31 30 29 28 27 26 25 24 debugevt forced ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? vecttbl ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 264 12.9.1.16memmanage fault address register name: scb_mmfar access: read/write the scb_mmfar contains the addr ess of the location that gener ated a memory management fault. ? address: memory management fault generation location address when the mmarvalid bit of the mmfsr subregi ster is set to 1, this field holds the address of the location that generated the memory management fault. notes: 1. when an unaligned access faults, the address is the actual address that faulted. becaus e a single read or write instruc tion can be split into multiple aligned accesses, the fault address can be any address in the range of the requested access size. 2. flags in the mmfsr subregister indicate the cause of the fault, and whether the value in the scb_mmfar is valid. see ?mmfsr: memory management fault status subregister? . 31 30 29 28 27 26 25 24 address 23 22 21 20 19 18 17 16 address 15 14 13 12 11 10 9 8 address 76543210 address
265 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.9.1.17bus fault address register name: scb_bfar access: read/write the scb_bfar contains the address of the location that generated a bus fault. ? address: bus fault generation location address when the bfarvalid bit of the bfsr subreg ister is set to 1, this field holds the address of the location that generated the bus fault. notes: 1. when an unaligned access faults, the address in the scb_bfar is the one requested by the in struction, even if it is not the address of the fault. 2. flags in the bfsr indicate the cause of the fault, and whether the value in the scb_bfar is valid. see ?bfsr: bus fault status subregister? . 31 30 29 28 27 26 25 24 address 23 22 21 20 19 18 17 16 address 15 14 13 12 11 10 9 8 address 76543210 address
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 266 12.10 system timer (systick) the processor has a 24-bit system timer, systick, that counts down from the reload value to zero, reloads (wraps to) the value in the syst_rvr on the next clock edge, then counts down on subsequent clocks. when the processor is halted for debugging, the counter does not decrement. the systick counter runs on the processo r clock. if this clock signal is stopped for low power mode, the systick counter stops. ensure that the software uses aligned wo rd accesses to access the systick registers. the systick counter reload and current value are undefined at reset; the correct initialization sequence for the systick counter is: 1. program the reload value. 2. clear the current value. 3. program the control and status register.
267 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.10.1 system timer (systick) user interface table 12-35. system timer (syst) register mapping offset register name access reset 0xe000e010 systick control and status register syst_csr read/write 0x00000000 0xe000e014 systick reload value r egister syst_rvr read/write unknown 0xe000e018 systick current value register syst_cvr read/write unknown 0xe000e01c systick calibration value register syst_calib read-only 0x000030d4
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 268 12.10.1.1systick control and status register name: syst_csr access: read/write the systick syst_csr enable s the systick features. ? countflag: count flag returns 1 if the timer counted to 0 since the last time this was read. ? clksource: clock source indicates the clock source: 0: external clock. 1: processor clock. ? tickint: systick exception request enable enables a systick exception request: 0: counting down to zero does not assert the systick exception request. 1: counting down to zero assert s the systick exception request. the software can use countflag to determi ne if systick has ever counted to zero. ? enable: counter enable enables the counter: 0: counter disabled. 1: counter enabled. when enable is set to 1, th e counter loads the reload va lue from the syst_rvr and then counts down. on reaching 0, it sets the countflag to 1 and optionally asserts the systick depending on the value of tickint. it then loads the reload value again, and begins counting. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? countflag 15 14 13 12 11 10 9 8 ? 76543210 clksource tickint enable
269 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.10.1.2systick reload value registers name: syst_rvr access: read/write the syst_rvr specifies the start va lue to load into the syst_cvr. ? reload: syst_cvr load value value to load into the syst_cvr when the counter is enab led and when it reaches 0. the reload value can be any value in the range 0x0000000 1?0x00ffffff. a start value of 0 is possible, but has no effect because the systick exception request and co untflag are activated when counting from 1 to 0. the reload value is calculated according to its use: for example, to gener ate a multi-shot timer with a period of n pro- cessor clock cycles, use a reload value of n-1. if the systi ck interrupt is required every 100 clock pulses, set reload to 99. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 reload 15 14 13 12 11 10 9 8 reload 76543210 reload
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 270 12.10.1.3systick current value register name: syst_cvr access: read/write the systick syst_cvr contains the current value of the systick counter. ? current: systick counter current value reads return the current value of the systick counter. a write of any value clears the field to 0, and also clears the syst_csr.countflag bit to 0. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 current 15 14 13 12 11 10 9 8 current 76543210 current
271 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.10.1.4systick calibration value register name: syst_calib access: read/write the systick syst_csr indicates th e systick calibration properties. ? noref: no reference clock it indicates whether the device provides a reference clock to the processor: 0: reference clock provided. 1: no reference clock provided. if your device does not provide a re ference clock, the syst_csr.clksource bit reads-as-one and ignores writes. ? skew: tenms value verification it indicates whether the tenms value is exact: 0: tenms value is exact. 1: tenms value is inexact, or not given. an inexact tenms value can affe ct the suitability of systick as a software real time clock. ? tenms: ten milliseconds the reload value for 10 ms (100 hz) timing is subject to system clock skew errors. if the va lue reads as ze ro, the calibra- tion value is not known. the tenms field default value is 0x000030d4 (12500 decimal). in order to achieve a 1 ms timebase on systtick, the tenm s field must be programmed to a value corresponding to the processor clock frequency (in khz) divided by 8. for example, for devices running the processor clock at 48 mhz, the tenms field value must be 0x0001770 (48000 khz/8) . 31 30 29 28 27 26 25 24 noref skew ? 23 22 21 20 19 18 17 16 tenms 15 14 13 12 11 10 9 8 tenms 76543210 tenms
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 272 12.11 memory protection unit (mpu) the mpu divides the memory map into a number of regions, and defines the location, size, access permissions, and memory attributes of each region. it supports: ? independent attribute settings for each region ? overlapping regions ? export of memory attr ibutes to the system. the memory attributes affect the behavior of memory accesses to the region. the cortex-m4 mpu defines: ? eight separate memory regions, 0?7 ? a background region. when memory regions overlap, a memo ry access is affected by the attr ibutes of the regi on with the highest number. for example, the attributes for region 7 take prec edence over the attributes of any region that overlaps region 7. the background region has the same memory access attr ibutes as the default memo ry map, but is accessible from privileged software only. the cortex-m4 mpu memory map is unified. this means t hat instruction accesses and data accesses have the same region settings. if a program accesses a memory location that is prohibited by the mpu, the processor generates a memory management fault. this causes a fault exception, and might cause the termination of the process in an os environment. in an os environment, the kernel can update the mpu r egion setting dynamically based on the process to be executed. typically, an embedded os us es the mpu for memory protection. the configuration of mpu regions is based on memory types (see ?memory regions, types and attributes? ). table 12-36 shows the possible mpu region attributes. these in clude share ability and cache behavior attributes that are not relevant to most microcontroller implementations. see ?mpu configuration for a microcontroller? for guidelines for programming such an implementation. 12.11.1 mpu access permission attributes this section describes the mpu access permission attributes . the access permission bits (tex, c, b, s, ap, and xn) of the mpu_rasr control the access to the corresponding memory region. if an access is made to an area of memory without the required permissions, then the mpu generates a permission fault. table 12-36. memory attributes summary memory type shareability other attributes description strongly-ordered ? ? all accesses to strongly-ordered memory occur in program order. all strongly-ordered regions are assumed to be shared. device shared ? memory-mapped peripherals that several processors share. non-shared ? memory-mapped peripherals that only a single processor uses. normal shared ? normal memory that is shared between several processors. non-shared ? normal memory that only a single processor uses.
273 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the table below shows the encodings for t he tex, c, b, and s access permission bits. note: 1. the mpu ignores the value of this bit. table 12-38 shows the cache policy for memory attribute encodings with a tex value is in the range 4?7. table 12-37. tex, c, b, and s encoding tex c b s memory type shareability other attributes b000 0 0 x (1) strongly-ordered shareable ? 1 x (1) device shareable ? 1 0 0 normal not shareable outer and inner write-through. no write allocate. 1 shareable 1 0 normal not shareable outer and inner write-back. no write allocate. 1 shareable b001 0 0 0 normal not shareable ? 1 shareable 1 x (1) reserved encoding ? 1 0 x (1) implementation defined attributes. ? 1 0 normal not shareable outer and inner write-back. write and read allocate. 1 shareable b010 0 0 x (1) device not shareable nonshared device. 1 x (1) reserved encoding ? 1x (1) x (1) reserved encoding ? b1bb a a 0 normal not shareable ? 1 shareable table 12-38. cache policy fo r memory attribute encoding encoding, aa or bb corresponding cache policy 00 non-cacheable 01 write back, write and read allocate 10 write through, no write allocate 11 write back, no write allocate
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 274 table 12-39 shows the ap encodings that define the access permissions for privileged and unprivileged software. 12.11.1.1mpu mismatch when an access violates the mpu permissions, the processor generates a memory management fault, see ?exceptions and interrupts? . the mmfsr indicates the cause of the fault. see ?mmfsr: memory management fault status subregister? for more information. 12.11.1.2updating an mpu region to update the attributes for an mpu region, update the mpu_rnr, mpu_rbar and mpu_rasrs. each register can be programed separately, or a multiple-word write ca n be used to program all of these registers. mpu_rbar and mpu_rasr aliases can be used to program up to four regions simultaneously using an stm instruction. 12.11.1.3updating an mpu region using separate words simple code to configure one region: ; r1 = region number ; r2 = size/enable ; r3 = attributes ; r4 = address ldr r0,=mpu_rnr ; 0xe000ed98, mpu region number register str r1, [r0, #0x0] ; region number str r4, [r0, #0x4] ; region base address strh r2, [r0, #0x8] ; region size and enable strh r3, [r0, #0xa] ; region attribute disable a region before writing new region settings to the mpu, if the regi on being changed was previously enabled. for example: ; r1 = region number ; r2 = size/enable ; r3 = attributes ; r4 = address ldr r0,=mpu_rnr ; 0xe000ed98, mpu region number register str r1, [r0, #0x0] ; region number bic r2, r2, #1 ; disable strh r2, [r0, #0x8] ; region size and enable str r4, [r0, #0x4] ; region base address strh r3, [r0, #0xa] ; region attribute orr r2, #1 ; enable table 12-39. ap encoding ap[2:0] privileged permissions unprivileged permissions description 000 no access no access all accesses generate a permission fault 001 rw no access access from privileged software only 010 rw ro writes by unprivileged software generate a permission fault 011 rw rw full access 100 unpredictable unpredictable reserved 101 ro no access reads by privileged software only 110 ro ro read only, by privileged or unprivileged software 111 ro ro read only, by privileged or unprivileged software
275 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 strh r2, [r0, #0x8] ; region size and enable the software must use memory barrier instructions: ? before the mpu setup, if there might be outstanding me mory transfers, such as buffered writes, that might be affected by the change in mpu settings ? after the mpu setup, if it includes memory transfers that must use the new mpu settings. however, memory barrier instructions are not required if the mpu setup process starts by entering an exception handler, or is followed by an exception return, because the exception entry and exception return mechanisms cause memory barrier behavior. the software does not need any memory barrier instructions during an mpu setup, because it accesses the mpu through the ppb, which is a strongly-ordered memory region. for example, if the user wants all of the memory access behavior to take effect immediately after the programming sequence, a dsb instruction and an isb instruction must be used. a dsb is required after changing mpu settings, such as at the end of a c ontext switch. an isb is required if the code that programs the mpu region or regions is entered using a branch or call. if the programming sequence is entered using a return from exception, or by taking an exception, then an isb is not required. 12.11.1.4updating an mpu region using multi-word writes the user can program directly using mu lti-word writes, depending on how the information is divided. consider the following reprogramming: ; r1 = region number ; r2 = address ; r3 = size, attributes in one ldr r0, =mpu_rnr ; 0xe000ed98, mpu region number register str r1, [r0, #0x0] ; region number str r2, [r0, #0x4] ; region base address str r3, [r0, #0x8] ; region attribute, size and enable use an stm instructio n to optimize this: ; r1 = region number ; r2 = address ; r3 = size, attributes in one ldr r0, =mpu_rnr ; 0xe000ed98, mpu region number register stm r0, {r1-r3} ; region number, address, attribute, size and enable this can be done in two words for pre-packed informatio n. this means that the mpu_ rbar contains the required region number and had the valid bit set to 1. see ?mpu region base address register? . use this when the data is statically packed, for example in a boot loader: ; r1 = address and region number in one ; r2 = size and attributes in one ldr r0, =mpu_rbar ; 0xe000ed9c, mpu region base register str r1, [r0, #0x0] ; region base address and ; region number combined with valid (bit 4) set to 1 str r2, [r0, #0x4] ; region attribute, size and enable use an stm instructio n to optimize this: ; r1 = address and region number in one ; r2 = size and attributes in one ldr r0,=mpu_rbar ; 0xe000ed9c, mpu region base register
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 276 stm r0, {r1-r2} ; region base address, region number and valid bit, ; and region attribute, size and enable 12.11.1.5subregions regions of 256 bytes or more are divided into eight equal -sized subregions. set the corresponding bit in the srd field of the mpu_rasr field to disable a subregion. see ?mpu region attribute and size register? . the least significant bit of srd controls the firs t subregion, and the most significant bi t controls the last subregion. disabling a subregion means another region overlapping the disabled range matches instead. if no other enabled region overlaps the disabled subregion, the mpu issues a fault. regions of 32, 64, and 128 bytes do not support subregions. with regions of these sizes, the srd field must be set to 0x00, otherwise the mpu behavior is unpredictable. 12.11.1.6example of srd use two regions with the same base address overlap. region 1 is 128 kb, and region 2 is 512 kb. to ensure the attributes from region 1 apply to the first 128 kb region, set the srd field for region 2 to b00000011 to disable the first two subregions, as in figure 12-13 below: figure 12-13. srd use 12.11.1.7mpu design hints and tips to avoid unexpected behavior, disable the interrupts before updating the attributes of a region that the interrupt handlers might access. ensure the software uses aligned accesses of the correct size to access mpu registers: ? except for the mpu_rasr, it mu st use aligned word accesses ? for the mpu_rasr, it can use byte or aligned halfword or word accesses. the processor does not support unaligned accesses to mpu registers. when setting up the mpu, and if the mpu has previously been programmed, disable unused regions to prevent any previous region settings from affecting the new mpu setup. mpu configuration fo r a microcontroller usually, a microcontroller system has only a single proc essor and no caches. in such a system, program the mpu as follows: region 1 disabled subregion disabled subregion region 2, with subregions base address of both regions offset from base address 0 64kb 128kb 192kb 256kb 320kb 384kb 448kb 512kb table 12-40. memory region attributes for a microcontroller memory region tex c b s memory type and attributes flash memory b000 1 0 0 normal memory, non-shareable, write-through internal sram b000 1 0 1 normal memory, shareable, write-through external sram b000 1 1 1 normal memory, s hareable, write-back, write-allocate peripherals b000 0 1 1 device memory, shareable
277 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 in most microcontroller im plementations, the shareability and cache policy attributes do not affect the system behavior. however, using these settings for the mpu regions can make the application code more portable. the values given are for typical situations. in special syst ems, such as multiprocesso r designs or designs with a separate dma engine, the shareability a ttribute might be importan t. in these cases, refe r to the re commendations of the memory device manufacturer.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 278 12.11.2 memory protection unit (mpu) user interface table 12-41. memory protection unit (mpu) register mapping offset register name access reset 0xe000ed90 mpu type register mpu_type read-only 0x00000800 0xe000ed94 mpu control register mpu_ctrl read/write 0x00000000 0xe000ed98 mpu region number register mpu_rnr read/write 0x00000000 0xe000ed9c mpu region base address register mpu_rbar read/write 0x00000000 0xe000eda0 mpu region attribute and size register mpu_rasr read/write 0x00000000 0xe000eda4 mpu region base address register alias 1 mpu_rbar_a1 read/write 0x00000000 0xe000eda8 mpu region attribute and size register alias 1 mpu_rasr_a1 read/write 0x00000000 0xe000edac mpu region base address register alias 2 mpu_rbar_a2 read/write 0x00000000 0xe000edb0 mpu region attribute and size register alias 2 mpu_rasr_a2 read/write 0x00000000 0xe000edb4 mpu region base address register alias 3 mpu_rbar_a3 read/write 0x00000000 0xe000edb8 mpu region attribute and size register alias 3 mpu_rasr_a3 read/write 0x00000000
279 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.11.2.1mpu type register name: mpu_type access: read/write the mpu_type register indicates whet her the mpu is present, and if so, how many regions it supports. ? iregion: instruction region indicates the number of supported mpu instruction regions. always contains 0x00. the mpu memory map is unified and is described by the dregion field. ? dregion: data region indicates the number of supported mpu data regions: 0x08 = eight mpu regions. ? separate: separate instruction indicates support for unified or separa te instruction and date memory maps: 0: unified. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 iregion 15 14 13 12 11 10 9 8 dregion 76543210 ? separate
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 280 12.11.2.2mpu control register name: mpu_ctrl access: read/write the mpu ctrl register enables the mpu, enables the def ault memory map background region, and enables the use of the mpu when in the hard fault, non-maskable in terrupt (nmi), and faul tmask escalated handlers. ? privdefena: privileged default memory map enable enables privileged software access to the default memory map: 0: if the mpu is enabled, disables the use of the default memory map. any memory access to a location not covered by any enabled region causes a fault. 1: if the mpu is enabled, enables the use of the default me mory map as a background region for privileged software accesses. when enabled, the background region acts as a region number -1 . any region that is defined and enabled has priority over this default map. if the mpu is disabled, the processor ignores this bit. ? hfnmiena: hard fault and nmi enable enables the operation of mpu during hard fault, nm i, and faultmask handlers. when the mpu is enabled: 0: mpu is disabled during hard fault, nmi, and faultmask handlers, rega rdless of the value of the enable bit. 1: the mpu is enabled during hard fault, nmi, and faultmask handlers. when the mpu is disabled, if this bit is set to 1, the behavior is unpredictable. ? enable: mpu enable enables the mpu: 0: mpu disabled. 1: mpu enabled. when enable and privdefena are both set to 1: ? for privileged accesses, the default memory map is as described in ?memory model? . any access by privileged software that does not address an enabled memory region behaves as defined by the default memory map. ? any access by unprivileged software that does not address an enabled memory region causes a memory management fault. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? privdefena hfnmiena enable
281 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 xn and strongly-ordered rules always apply to the system control space regardless of the value of the enable bit. when the enable bit is set to 1, at least one region of the memory map must be enabled for the system to function unless the privdefena bit is set to 1. if the privdefena bit is se t to 1 and no regions are enabled, then only privileged soft- ware can operate. when the enable bit is set to 0, the system uses the default memory map. this has the same memory attributes as if the mpu is not implemented. the default memory map applies to accesses from both privileged and unprivileged software. when the mpu is enabled, accesses to the system control sp ace and vector table are always permitted. other areas are accessible based on regions and whether privdefena is set to 1. unless hfnmiena is set to 1, the mpu is not enabled when the processor is executing the handler for an exception with priority ?1 or ?2. these priorities are only possible when handling a hard fault or nmi ex ception, or when faultmask is enabled. setting the hfnmiena bit to 1 enables th e mpu when operating with these two priorities.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 282 12.11.2.3mpu region number register name: mpu_rnr access: read/write the mpu_rnr selects which memo ry region is referenced by the mpu_rbar and mpu_rasrs. ? region: mpu region referenced by the mpu_rbar and mpu_rasrs indicates the mpu region referenced by the mpu_rbar and mpu_rasrs. the mpu supports 8 memory regions, so t he permitted values of this field are 0?7. normally, the required region number is written to this register before accessing the mpu_rbar or mpu_rasr. how- ever, the region number can be chan ged by writing to the mpu_rbar with the valid bit set to 1; see ?mpu region base address register? . this write updates the value of the region field. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 region
283 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.11.2.4mpu region base address register name: mpu_rbar access: read/write the mpu_rbar defines the base address of the mpu region selected by the mpu_rnr, and can update the value of the mpu_rnr. write mpu_rbar with the valid bit set to 1 to change the current region number and update the mpu_rnr. ? addr: region base address software must ensure that the value written to the addr field a ligns with the size of the selected region (size field in the mpu_rasr). if the region size is configured to 4 gb, in the mpu_rasr, th ere is no valid addr field. in this case, the region occupies the complete memory map, and the base address is 0x00000000. the base address is aligned to the size of the region. for ex ample, a 64 kb region must be aligned on a multiple of 64 kb, for example, at 0x00010000 or 0x00020000. ? valid: mpu region number valid write: 0: mpu_rnr not changed, and the processor updates the base address for the region specified in the mpu_rnr, and ignores the value of the region field. 1: the processor updates the value of the mpu_rnr to the value of the region field, and updates the base address for the region specified in the region field. always reads as zero. ? region: mpu region for the behavior on writes, see the description of the valid field. on reads, returns the current region number, as specified by the mpu_rnr. 31 30 29 28 27 26 25 24 addr 23 22 21 20 19 18 17 16 addr 15 14 13 12 11 10 9 8 addr 76543210 addr valid region
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 284 12.11.2.5mpu region attribute and size register name: mpu_rasr access: read/write the mpu_rasr defines the region size and memory attribut es of the mpu region specified by the mpu_rnr, and enables that region and any subregions. mpu_rasr is accessible using word or halfword accesses: ? the most significant halfword holds the region attributes. ? the least significant halfword holds the region size, and the region and subregion enable bits. ? xn: instruction access disable 0: instruction fetches enabled. 1: instruction fetches disabled. ? ap: access permission see table 12-39 . ? tex, c, b: memory access attributes see table 12-37 . ? s: shareable see table 12-37 . ? srd: subregion disable for each bit in this field: 0: corresponding subregion is enabled. 1: corresponding subr egion is disabled. see ?subregions? for more information. region sizes of 128 bytes and less do not support subregions. when writing the attributes for such a region, write the srd field as 0x00. 31 30 29 28 27 26 25 24 ?x n ?a p 23 22 21 20 19 18 17 16 ?t e xs c b 15 14 13 12 11 10 9 8 srd 76543210 ?s i z e e n a b l e
285 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? size: size of the mpu protection region the minimum permitted value is 3 (b00010). the size field defines the size of the mpu memo ry region specified by the mpu_rnr. as follows: (region size in bytes) = 2 (size+1) the smallest permitted region size is 32 b, corresponding to a size value of 4. the table below gives an example of size values, with the corresponding region size and value of n in the mpu_rbar. note: 1. in the mpu_rbar; see ?mpu region base address register? ? enable: region enable note: for information about access permission, see ?mpu access permission attributes? . size value region size value of n (1) note b00100 (4) 32 b 5 minimum permitted size b01001 (9) 1 kb 10 ? b10011 (19) 1 mb 20 ? b11101 (29) 1 gb 30 ? b11111 (31) 4 gb b01100 maximum possible size
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 286 12.11.2.6mpu region base address register alias 1 name: mpu_rbar_a1 access: read/write the mpu_rbar defines the base address of the mpu region selected by the mpu_rnr, and can update the value of the mpu_rnr. write mpu_rbar with the valid bit set to 1 to change the current region number and update the mpu_rnr. ? addr: region base address software must ensure that the valu e written to the addr field aligns wit h the size of the selected region. the value of n depends on the region size. the addr field is bits[31:n] of the mpu_rbar. the region size, as specified by the size field in the mpu_rasr, defines the value of n: n = log2(region size in bytes), if the region size is configured to 4 gb, in the mpu_rasr, th ere is no valid addr field. in this case, the region occupies the complete memory map, and the base address is 0x00000000. the base address is aligned to the size of the region. for ex ample, a 64 kb region must be aligned on a multiple of 64 kb, for example, at 0x00010000 or 0x00020000. ? valid: mpu region number valid write: 0: mpu_rnr not changed, and the processor updates the base address for the region specified in the mpu_rnr, and ignores the value of the region field. 1: the processor updates the value of the mpu_rnr to the value of the region field, and updates the base address for the region specified in the region field. always reads as zero. ? region: mpu region for the behavior on writes, see the description of the valid field. on reads, returns the current region number, as specified by the mpu_rnr. 31 30 29 28 27 26 25 24 addr 23 22 21 20 19 18 17 16 addr 15 14 13 12 11 10 9 8 addr 76543210 addr valid region
287 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.11.2.7mpu region attribute and size register alias 1 name: mpu_rasr_a1 access: read/write the mpu_rasr defines the region size and memory attribut es of the mpu region specified by the mpu_rnr, and enables that region and any subregions. mpu_rasr is accessible using word or halfword accesses: ? the most significant halfword holds the region attributes. ? the least significant halfword holds the region size, and the region and subregion enable bits. ? xn: instruction access disable 0: instruction fetches enabled. 1: instruction fetches disabled. ? ap: access permission see table 12-39 . ? tex, c, b: memory access attributes see table 12-37 . ? s: shareable see table 12-37 . ? srd: subregion disable for each bit in this field: 0: corresponding subregion is enabled. 1: corresponding subr egion is disabled. see ?subregions? for more information. region sizes of 128 bytes and less do not support subregions. when writing the attributes for such a region, write the srd field as 0x00. 31 30 29 28 27 26 25 24 ?x n ?a p 23 22 21 20 19 18 17 16 ?t e xs c b 15 14 13 12 11 10 9 8 srd 76543210 ?s i z e e n a b l e
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 288 ? size: size of the mpu protection region the minimum permitted value is 3 (b00010). the size field defines the size of the mpu memo ry region specified by the mpu_rnr. as follows: (region size in bytes) = 2 (size+1) the smallest permitted region size is 32 b, corresponding to a size value of 4. the table below gives an example of size values, with the corresponding region size and value of n in the mpu_rbar. note: 1. in the mpu_rbar; see ?mpu region base address register? ? enable: region enable note: for information about access permission, see ?mpu access permission attributes? . size value region size value of n (1) note b00100 (4) 32 b 5 minimum permitted size b01001 (9) 1 kb 10 ? b10011 (19) 1 mb 20 ? b11101 (29) 1 gb 30 ? b11111 (31) 4 gb b01100 maximum possible size
289 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.11.2.8mpu region base address register alias 2 name: mpu_rbar_a2 access: read/write the mpu_rbar defines the base address of the mpu region selected by the mpu_rnr, and can update the value of the mpu_rnr. write mpu_rbar with the valid bit set to 1 to change the current region number and update the mpu_rnr. ? addr: region base address software must ensure that the valu e written to the addr field aligns wit h the size of the selected region. the value of n depends on the region size. the addr field is bits[31:n] of the mpu_rbar. the region size, as specified by the size field in the mpu_rasr, defines the value of n: n = log2(region size in bytes), if the region size is configured to 4 gb, in the mpu_rasr, th ere is no valid addr field. in this case, the region occupies the complete memory map, and the base address is 0x00000000. the base address is aligned to the size of the region. for ex ample, a 64 kb region must be aligned on a multiple of 64 kb, for example, at 0x00010000 or 0x00020000. ? valid: mpu region number valid write: 0: mpu_rnr not changed, and the processor updates the base address for the region specified in the mpu_rnr, and ignores the value of the region field. 1: the processor updates the value of the mpu_rnr to the value of the region field, and updates the base address for the region specified in the region field. always reads as zero. ? region: mpu region for the behavior on writes, see the description of the valid field. on reads, returns the current region number, as specified by the mpu_rnr. 31 30 29 28 27 26 25 24 addr 23 22 21 20 19 18 17 16 addr 15 14 13 12 11 10 9 8 addr 76543210 addr valid region
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 290 12.11.2.9mpu region attribute and size register alias 2 name: mpu_rasr_a2 access: read/write the mpu_rasr defines the region size and memory attribut es of the mpu region specified by the mpu_rnr, and enables that region and any subregions. mpu_rasr is accessible using word or halfword accesses: ? the most significant halfword holds the region attributes. ? the least significant halfword holds the region size, and the region and subregion enable bits. ? xn: instruction access disable 0: instruction fetches enabled. 1: instruction fetches disabled. ? ap: access permission see table 12-39 . ? tex, c, b: memory access attributes see table 12-37 . ? s: shareable see table 12-37 . ? srd: subregion disable for each bit in this field: 0: corresponding subregion is enabled. 1: corresponding subr egion is disabled. see ?subregions? for more information. region sizes of 128 bytes and less do not support subregions. when writing the attributes for such a region, write the srd field as 0x00. 31 30 29 28 27 26 25 24 ?x n ?a p 23 22 21 20 19 18 17 16 ?t e xs c b 15 14 13 12 11 10 9 8 srd 76543210 ?s i z e e n a b l e
291 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? size: size of the mpu protection region the minimum permitted value is 3 (b00010). the size field defines the size of the mpu memo ry region specified by the mpu_rnr. as follows: (region size in bytes) = 2 (size+1) the smallest permitted region size is 32 b, corresponding to a size value of 4. the table below gives an example of size values, with the corresponding region size and value of n in the mpu_rbar. note: 1. in the mpu_rbar; see ?mpu region base address register? ? enable: region enable note: for information about access permission, see ?mpu access permission attributes? . size value region size value of n (1) note b00100 (4) 32 b 5 minimum permitted size b01001 (9) 1 kb 10 ? b10011 (19) 1 mb 20 ? b11101 (29) 1 gb 30 ? b11111 (31) 4 gb b01100 maximum possible size
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 292 12.11.2.10mpu region base address register alias 3 name: mpu_rbar_a3 access: read/write the mpu_rbar defines the base address of the mpu region selected by the mpu_rnr, and can update the value of the mpu_rnr. write mpu_rbar with the valid bit set to 1 to change the current region number and update the mpu_rnr. ? addr: region base address software must ensure that the valu e written to the addr field aligns wit h the size of the selected region. the value of n depends on the region size. the addr field is bits[31:n] of the mpu_rbar. the region size, as specified by the size field in the mpu_rasr, defines the value of n: n = log2(region size in bytes), if the region size is configured to 4 gb, in the mpu_rasr, th ere is no valid addr field. in this case, the region occupies the complete memory map, and the base address is 0x00000000. the base address is aligned to the size of the region. for ex ample, a 64 kb region must be aligned on a multiple of 64 kb, for example, at 0x00010000 or 0x00020000. ? valid: mpu region number valid write: 0: mpu_rnr not changed, and the processor updates the base address for the region specified in the mpu_rnr, and ignores the value of the region field. 1: the processor updates the value of the mpu_rnr to the value of the region field, and updates the base address for the region specified in the region field. always reads as zero. ? region: mpu region for the behavior on writes, see the description of the valid field. on reads, returns the current region number, as specified by the mpu_rnr. 31 30 29 28 27 26 25 24 addr 23 22 21 20 19 18 17 16 addr 15 14 13 12 11 10 9 8 addr 76543210 addr valid region
293 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.11.2.11mpu region attribute and size register alias 3 name: mpu_rasr_a3 access: read/write the mpu_rasr defines the region size and memory attribut es of the mpu region specified by the mpu_rnr, and enables that region and any subregions. mpu_rasr is accessible using word or halfword accesses: ? the most significant halfword holds the region attributes. ? the least significant halfword holds the region size, and the region and subregion enable bits. ? xn: instruction access disable 0: instruction fetches enabled. 1: instruction fetches disabled. ? ap: access permission see table 12-39 . ? tex, c, b: memory access attributes see table 12-37 . ? s: shareable see table 12-37 . ? srd: subregion disable for each bit in this field: 0: corresponding subregion is enabled. 1: corresponding subr egion is disabled. see ?subregions? for more information. region sizes of 128 bytes and less do not support subregions. when writing the attributes for such a region, write the srd field as 0x00. 31 30 29 28 27 26 25 24 ?x n ?a p 23 22 21 20 19 18 17 16 ?t e xs c b 15 14 13 12 11 10 9 8 srd 76543210 ?s i z e e n a b l e
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 294 ? size: size of the mpu protection region the minimum permitted value is 3 (b00010). the size field defines the size of the mpu memo ry region specified by the mpu_rnr. as follows: (region size in bytes) = 2 (size+1) the smallest permitted region size is 32 b, corresponding to a size value of 4. the table below gives an example of size values, with the corresponding region size and value of n in the mpu_rbar. note: 1. in the mpu_rbar; see ?mpu region base address register? ? enable: region enable note: for information about access permission, see ?mpu access permission attributes? . size value region size value of n (1) note b00100 (4) 32 b 5 minimum permitted size b01001 (9) 1 kb 10 ? b10011 (19) 1 mb 20 ? b11101 (29) 1 gb 30 ? b11111 (31) 4 gb b01100 maximum possible size
295 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.12 floating point unit (fpu) the cortex-m4f fpu implements the fpv4-sp floating-point extension. the fpu fully supports single-precision add, subtract, multiply, divide, multiply and accumulate, and square root operations. it also provides conver sions between fixed-point and floating-point data fo rmats, and floating-point constant instructions. the fpu provides floating-point computation functional ity that is compliant with the ansi/ieee std 754-2008, ieee standard for binary floatin g-point arithmetic, referred to as the ieee 754 standard. the fpu contains 32 single-precision ex tension registers, which can also be accessed as 16 doubleword registers for load, store, and move operations. 12.12.1 enabling the fpu the fpu is disabled from reset. it must be enabled before any floating-point instructions can be used. example 4- 1 shows an example code sequence for enabling the fpu in both privileged and user modes. the processor must be in privileged mode to read from and write to the cpacr. example of enabling the fpu: ; cpacr is located at address 0xe000ed88 ldr.w r0, =0xe000ed88 ; read cpacr ldr r1, [r0] ; set bits 20-23 to enable cp10 and cp11 coprocessors orr r1, r1, #(0xf << 20) ; write back the modified value to the cpacr str r1, [r0]; wait for store to complete dsb ;reset pipeline now the fpu is enabled isb
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 296 12.12.2 floating point unit (fpu) user interface table 12-42. floating point unit (fpu) register mapping offset register name access reset 0xe000ed88 coprocessor access control register cpacr read/write 0x00000000 0xe000ef34 floating-point context control register fpccr read/write 0xc0000000 0xe000ef38 floating-point context address register fpcar read/write ? ? floating-point status control register fpscr read/write ? 0xe000e01c floating-point default status control register fpdscr read/write 0x00000000
297 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.12.2.1coprocessor access control register name: cpacr access: read/write the cpacr specifies the access privileges for coprocessors. ? cp10: access privileges for coprocessor 10 the possible values of each field are: 0: access denied. any attempted access generates a nocp usagefault. 1: privileged access only. an unprivileged access generates a nocp fault. 2: reserved. the result of any access is unpredictable. 3: full access. ? cp11: access privileges for coprocessor 11 the possible values of each field are: 0: access denied. any attempted access generates a nocp usagefault. 1: privileged access only. an unprivileged access generates a nocp fault. 2: reserved. the result of any access is unpredictable. 3: full access. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 cp11 cp10 ? 15 14 13 12 11 10 9 8 ? 76543210 ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 298 12.12.2.2floating-point context control register name: fpccr access: read/write the fpccr sets or retu rns fpu control data. ? aspen: automatic hardware state preservation and restoration enables control bit [2] setting on executio n of a floating-point instruction. this results in an automatic hardware state preservation and restoration, for floating-po int context, on exception entry and exit. 0: disable control bit [2] setting on ex ecution of a floating-point instruction. 1: enable control bit [2] setting on exec ution of a floating-point instruction. ? lspen: automatic lazy state preservation 0: disable automatic lazy state preservation for floating-point context. 1: enable automatic lazy state pres ervation for floating-point context. ? monrdy: debug monitor ready 0: debugmonitor is disabled or the priority did not permit to set mon_pend when the floating-point stack frame was allocated. 1: debugmonitor is enabled and the priority permitted to set mon_pend when the fl oating-point stack frame was allocated. ? bfrdy: bus fault ready 0: busfault is disabled or the priority did not permit to se t the busfault handler to the pending state when the floating-point stack frame was allocated. 1: busfault is enabled and the priority permitted to set the busfault handler to the pending state when the floating-point stack frame was allocated. ? mmrdy: memory management ready 0: memmanage is disabled or the priority did not permit to set the memmanage handler to the pending state when the float- ing-point stack frame was allocated. 1: memmanage is enabled and the priority permitted to se t the memmanage handler to the pending state when the float- ing-point stack frame was allocated. 31 30 29 28 27 26 25 24 aspen lspen ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? monrdy 76543210 ? bfrdy mmrdy hfrdy thread ? user lspact
299 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? hfrdy: hard fault ready 0: the priority did not permit to set the hardfault handler to the pending state when the floating-point stack frame was allocated. 1: the priority permitted to set the ha rdfault handler to the pending state when the floating-point stack frame was allocated. ? thread: thread mode 0: the mode was not the thread mode when the floating-point stack frame was allocated. 1: the mode was the thread mode when the floating-point stack frame was allocated. ? user: user privilege level 0: the privilege leve l was not user when the floating-point stack frame was allocated. 1: the privilege level was user when the floating-point stack frame was allocated. ? lspact: lazy state preservation active 0: the lazy state preservation is not active. 1: the lazy state preservation is active. the floating-point stack frame has been allocated but saving the state to it has been deferred.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 300 12.12.2.3floating-point context address register name: fpcar access: read/write the fpcar holds the location of the unpopulated floating-poi nt register space allocated on an exception stack frame. ? address: location of unpopulated floating-point register space allocated on an exception stack frame the location of the unpopulated floating-point regist er space allocated on an exception stack frame. 31 30 29 28 27 26 25 24 address 23 22 21 20 19 18 17 16 address 15 14 13 12 11 10 9 8 address 76543210 address ?
301 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.12.2.4floating-point status control register name: fpscr access: read/write the fpscr provides all necessary user le vel control of the floating-point system. ? n: negative condition code flag floating-point comparison operations update this flag. ? z: zero condition code flag floating-point comparison operations update this flag. ? c: carry condition code flag floating-point comparison operations update this flag. ? v: overflow condition code flag floating-point comparison operations update this flag. ? ahp: alternative half-precision control 0: ieee half-precisio n format selected. 1: alternative half-precision format selected. ? dn: default nan mode control 0: nan operands propagate through to the output of a floating-point operation. 1: any operation involving one or more nans returns the default nan. ? fz: flush-to-zero mode control 0: flush-to-zero mode disabled. th e behavior of the floating-poi nt system is fully compliant with the ieee 754 standard. 1: flush-to-zero mode enabled. ? rmode: rounding mode control the encoding of this field is: 0b00: round to nearest (rn) mode 0b01: round towards plus infinity (rp) mode. 0b10: round towards minus infinity (rm) mode. 31 30 29 28 27 26 25 24 n z c v ? ahp dn fz 23 22 21 20 19 18 17 16 rmode ? 15 14 13 12 11 10 9 8 ? 76543210 idc ? ixc ufc ofc dzc ioc
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 302 0b11: round towards zero (rz) mode. the specified rounding mode is used by almost all floating-point instructions. ? idc: input denormal cumulative exception idc is a cumulative exceptio n bit for floating-point exception; see also bits [4:0]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? ixc: inexact cumulative exception ixc is a cumulative exception bit for floa ting-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? ufc: underflow cumulative exception ufc is a cumulative exception bit for float ing-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? ofc: overflow cumulative exception ofc is a cumulative exception bit for floa ting-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? dzc: division by zero cumulative exception dzc is a cumulative exception bit for float ing-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? ioc: invalid operation cumulative exception ioc is a cumulative exception bit for floa ting-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it.
303 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 12.12.2.5floating-point default status control register name: fpdscr access: read/write the fpdscr holds the default values for the floating-point status control data. ? ahp: fpscr.ahp default value default value for fpscr.ahp. ? dn: fpscr.dn default value default value for fpscr.dn. ? fz: fpscr.fz default value default value for fpscr.fz. ? rmode: fpscr.rmode default value default value for fpscr.rmode. 31 30 29 28 27 26 25 24 ? ahp dn fz 23 22 21 20 19 18 17 16 rmode ? 15 14 13 12 11 10 9 8 ? 76543210 ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 304 12.13 glossary this glossary describes some of the terms used in technical documents from arm. abort a mechanism that indicates to a pr ocessor that the value associated with a memory access is invalid. an abort can be caused by the external or internal memory system as a result of attempting to access invalid instruction or data memory. aligned a data item stored at an address that is divisible by the number of bytes that defines the data size is said to be aligned. aligned words and halfwords have addresses that are divisible by four and two respectively. the terms word-aligned and halfword -aligned therefore stipulate addresses that are divisible by four and two respectively. banked register a register that has multiple physical copies, where the state of the processor determines which copy is used. the stack pointer, sp (r13) is a banked register. base register in instruction descriptions, a register specified by a load or store instruction t hat is used to hold the base value for the instruction?s address calculation. depending on the instruction and its addressing mode, an offset can be added to or subtracted from the base register value to form the address that is sent to memory. see also ?index register? . big-endian (be) byte ordering scheme in which bytes of decreas ing significance in a data word are stored at increasing addresses in memory. see also ?byte-invariant? , ?endianness? , ?little-endian (le)? . big-endian memory memory in which: a byte or halfword at a word-aligned address is the mo st significant byte or ha lfword within the word at that address, a byte at a halfword-aligned address is the most sign ificant byte within the halfword at that address. see also ?little-endian memory? . breakpoint a breakpoint is a mechanism provided by debugger s to identify an instruction at which program execution is to be halted. breakpoints are inserted by the programmer to enable inspection of register contents, memory locations, variable values at fixed points in the pr ogram execution to test that the program is operating correctly. breakpoints are remo ved after the program is successfully tested.
305 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 byte-invariant in a byte-invariant system, the address of each by te of memory remains unchanged when switching between little-endian and big-endian operation. when a data item larger than a byte is loaded from or stored to memory, the bytes making up that data item are arranged into the correct order depending on the endianness of the memory access. an arm byte-invariant implementation also suppor ts unaligned halfword and word memory accesses. it expects multi-word accesses to be word-aligned. condition field a four-bit field in an instruction that specifies a condition under which t he instruction can execute. conditional execution if the condition code flags indicate that the correspond ing condition is true when the instruction starts executing, it executes normally. ot herwise, the instruction does nothing. context the environment that each process operates in for a multita sking operating system. in arm processors, this is limited to mean the physical address range that it can access in memory and the associated memory access permissions. coprocessor a processor that supplements the main processor. cortex-m4 does not support any coprocessors. debugger a debugging system that includes a program, used to detect, locate, and correct software faults, together with custom hardware that supports software debugging. direct memory access (dma) an operation that accesses main memory directly , without the processor performing any accesses to the data concerned. doubleword a 64-bit data item. the contents are taken as be ing an unsigned integer unless otherwise stated. doubleword-aligned a data item having a memory address that is divisible by eight. endianness byte ordering. the scheme that dete rmines the order that successive bytes of a data word are stored in memory. an aspect of th e system?s memory mapping. see also ?little-endian (le)? and ?big-endian (be)? . exception an event that interrupts program execution. wh en an exception occurs, the processor suspends the normal program flow and starts execution at the address indicated by the corresponding exception vector. the indicated address contains the first instruction of the handler for the exception. an exception can be an in terrupt request, a fault, or a softwa re-generated system exception. faults include attempting an invalid memory access, attempting to execute an instruction in an invalid processor state, and attempting to execute an undefined instruction.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 306 exception service routine see ?interrupt handler? . exception vector see ?interrupt vector? . flat address mapping a system of organizing memory in which each physical address in the memory space is the same as the corresponding virtual address. halfword a 16-bit data item. illegal instruction an instruction th at is architecturally undefined. implementation-defined the behavior is not architecturally defined, but is defined and documented by individual implementations. implementation-specific the behavior is not architecturally defined, and does not have to be documented by individual implementations. used when there are a number of implementation options available and the option chosen does not affect software compatibility. index register in some load and store instruction descriptions, the value of this register is used as an offset to be added to or subtracted from the base register value to form the address that is sent to memory. some addressing modes optionally enable the index register value to be shifted prior to the addition or subtraction. see also ?base register? . instruction cycle count the number of cycles that an instruction occupies the execute stag e of the pipeline. interrupt handler a program that control of the pr ocessor is passed to wh en an interrupt occurs. interrupt vector one of a number of fixed addresses in low memory, or in high memory if high vectors are configured, that contains the first instruction of the corresponding interrupt handler. little-endian (le) byte ordering scheme in which bytes of increasing significance in a data word are stored at increasing addresses in memory. see also ?big-endian (be)? , ?byte-invariant? , ?endianness? .
307 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 little-endian memory memory in which: a byte or halfword at a word-aligned address is the l east significant byte or ha lfword within the word at that address, a byte at a halfword-aligned address is the least signi ficant byte within the half word at that address. see also ?big-endian memory? . load/store architecture a processor architecture where data-processing oper ations only operate on register contents, not directly on memory contents. memory protection unit (mpu) hardware that cont rols access permissions to blocks of memory. an mpu does not perform any address translation. prefetching in pipelined processors, the process of fetching instru ctions from memory to fill up the pipeline before the preceding instructions have fi nished executing. prefetching an instruction does not mean that the instruction has to be executed. preserved preserved by writing the same va lue back that has been previously read from the same field on the same processor. read reads are defined as memory operations that have the semantics of a load. reads include the thumb instructions ldm, ldr, ldrsh, ldrh, ldrsb, ldrb, and pop. region a partition of memory space. reserved a field in a control register or instruction format is reserved if the field is to be defined by the implementation, or produces unpredictable results if the contents of t he field are not zero. these fields are reserved for use in future extensions of th e architecture or are implementation-specific. all reserved bits not used by the implementation must be written as 0 and read as 0. thread-safe in a multi-tasking environment, thread-safe functions use safeguard mechanisms when accessing shared resources, to ensure correct operation without the risk of shared access conflicts. thumb instruction one or two halfwords that specify an operation for a processor to perf orm. thumb instructions must be halfword-aligned. unaligned a data item stored at an address that is not divisible by the number of bytes t hat defines the data size is said to be unaligned. for example, a word stor ed at an address that is not divisible by four.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 308 undefined indicates an instruction that generates an undefined instruction exception. unpredictable one cannot rely on the behavior. unpredictable behavior must not represent security holes. unpredictable behavior must not halt or hang the processor, or any parts of the system. warm reset also known as a core reset. initializes the majority of the processor excluding the debug controller and debug logic. this type of reset is useful if debugging features of a processor. word a 32-bit data item. write writes are defined as operations that have the semantics of a st ore. writes include the thumb instructions stm, str, strh, strb, and push.
309 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 13. debug and test features 13.1 description the sam4 series microcontrollers feature a number of complementary debug and test capabilities. the serial wire/jtag debug port (swj-dp) combining a serial wi re debug port (sw-dp) and jtag debug (jtag-dp) port is used for standard debugging functi ons, such as downloading code and single-stepping through programs. it also embeds a serial wire trace. 13.2 associated documentation the standard arm coresight ? macrocell is implemented in the devices. for further information on coresight, the following reference documents are available from the arm website: ? cortex-m4/m4f technical refer ence manual (arm ddi 0439c) ? coresight technology system design guide (arm dgi 0012d) ? coresight components technical reference manual (arm ddi 0314h) ? arm debug interface v5 architecture specification (doc. arm ihi 0031a) ? armv7-m architecture reference manual (arm ddi 0403d) 13.3 embedded characteristics ? dual core debugging with common serial wire debug port (sw-dp) and serial wire jtag debug port (swj-dp) debug access port connected to both cores. ? star topology ahb-ap debug access port implementation with common sw-dp / swj-dp providing higher performance than daisy-chain topology. ? possibility to halt each core on deb ug event on the other core (hardware) ? possibility to restart each core when th e other core has re started (hardware) ? synchronization and software cross-triggering with debugger ? intrumentation trace macrocell (itm) on both core for support of printf style debugging ? mux 2-1 to trace chosen core (limit the number of out put pin) ? single wire viewer or clock mode (4-bit parallel output ports) ? debug access to all memory and registers in the system, including cortex-m4 register bank when the core is running, halted, or held in reset. ? flash patch and breakpoint (fpb) unit for implementing breakpoints and code patches ? data watchpoint and trace (dwt) unit for implementin g watch points, data trac ing, and system profiling ? ieee?1149.1 jtag boundary scan on all digital pins
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 310 figure 13-1. debug and test block diagram tst tms tck/swclk tdi jtagsel tdo/traceswo boundary ta p swj-dp reset and test por
311 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 13-2. dual core debug architecture the above figure depicts the dual core debug implemen tation using only one sw -jtag/sw-dp debug access port. star topology has been used to connect the ahb-ap 0 (core 0) and ahb-ap 1 (core) rather than legacy daisy chainning method. it is providing higher performanc e than daisy-chain topology. this core debug architecture is fully supported by debug tools vendors. tdi tdo tms/swdio tck/swclk jtagsel serial wire and jtag debug port (sw-dp / swj-dp) cross-trigering debug event (halt / restart) cortex-m4f core 1 (cm4p1) dap rom tpiu 2 -> 1 dap rom tpiu cortex-m4 core 0 (cm4p0) ahb-ap 1 itm itm trace data ahb-ap 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 312 13.4 cross triggering debut events the cross triggerring (ct) as shown in the above figure is an atmel module allowing the two cores to send and receive debug events to and from each other. it might be needed to debug two applications at the same time (one application running on each core). for that case, the ct allows core 0 (or 1) to trig a debug event (halt) to core 1 (or 0) to enter debug mode. the debug event can be sent when the core 0 (or 1) is enter ing debug mode (such as brealpoint) or at run-time. it means that an user application running on core 0 (or 1) can put core 1 (or 0) without entering debug mode. once core 0 (or 1) gets out of debug mode, it releases core 1 (0) from debug mode as well. the cross trigerring configuration is located in the special function regi ster in the matrix user interface. 13.5 application examples 13.5.1 debug environment figure 13-3 shows a complete debug environment example. the swj-dp interface is used for standard debugging functions, such as downloading code and single-stepping through the program and viewing core and peripheral registers. figure 13-3. application debug environment example sam4 host debu gger pc sam4-based application board swj-dp connector swj-dp em ulator/probe
313 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 13.5.2 test environment figure 13-4 shows a test environment example (jtag boundary scan). test vectors are sent and interpreted by the tester. in this example, the ?boa rd in test? is designed using a number of jtag-compliant devices. these devices can be connected to form a single scan chain. figure 13-4. application test environment example 13.6 debug and test pin description chip 2 chip n chip 1 sam4 sam4-based application boa rd in test jtag connector te ster te st adaptor jtag probe table 13-1. debug and test signal list signal name function type active level reset/test nrst microcontroller reset input/output low tst test select input swd/jtag tck/swclk test clock/serial wire clock input tdi test data in input tdo/traceswo test data out/trace asynchronous data out output tms/swdio test mode select/serial wire input/output input jtagsel jtag selection input high
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 314 13.7 functional description 13.7.1 test pin one dedicated pin, tst, is used to define the device o perating mode. when this pin is at low level during power- up, the device is in normal operating mode. when at high level, the device is in test mode or ffpi mode. the tst pin integrates a permanent pull -down resistor of about 15 k , so that it can be left unconnected for normal operation. note that when setting the ts t pin to low or high level at power up , it must remain in the same state during the duration of the whole operation. 13.7.2 debug architecture figure 13-5 shows the debug architecture used in the sam4. the cortex-m4 embeds four functional units for debug: ? swj-dp (serial wire/jtag debug port) ? fpb (flash pa tch breakpoint) ? dwt (data watchpoint and trace) ? itm (instrumentation trace macrocell) ? tpiu (trace port interface unit) the debug architecture information that follows is mainly dedicated to developers of swj-dp emulators/probes and debugging tool vendors for cortex-m4 based microcon trollers. for further details on swj-dp see the cortex- m4 technical reference manual. figure 13-5. debug architecture 4 watchpoints pc sampler data address sampler data sampler interrupt trace cpu statistics dwt 6 breakpoints fpb software trace 32 channels time stamping itm swd/jtag swj-dp swo trace tpiu
315 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 13.7.3 serial wire/jtag debug port (swj-dp) the cortex-m4 embeds a swj-dp debug port which is the standard coresight debug port. it combines serial wire debug port (sw-dp), from 2 to 3 pins and jtag debug port (jtag-dp), 5 pins. by default, the jtag debug port is active. if the host debug ger wants to switch to the serial wire debug port, it must provide a dedicated jtag sequence on tms/ swdio and tck/swclk which disables jtag-dp and enables sw-dp. when the serial wire debug port is active, tdo/tra ceswo can be used for trace. the asynchronous trace output (traceswo) is multiplexed with tdo. so the asynchronous trace can only be used with sw-dp, not jtag-dp. sw-dp or jtag-dp mode is selected when jtagsel is low. it is not possibl e to switch directly between swj-dp and jtag boundary scan operations. a chip reset must be performed after jtagsel is changed. 13.7.3.1 sw-dp and jtag-dp selection mechanism debug port selection mechanism is done by sending specific swdiotms sequence. the jtag-dp is selected by default after reset. ? switch from jtag-dp to sw-dp. the sequence is: ? send more than 50 swclktck cycles with swdiotms = 1 ? send the 16-bit sequence on swdiotms = 0111100111100111 (0x79e7 msb first) ? send more than 50 swclktck cycles with swdiotms = 1 ? switch from swd to jtag. the sequence is: ? send more than 50 swclktck cycles with swdiotms = 1 ? send the 16-bit sequence on swdiotms = 0011110011100111 (0x3ce7 msb first) ? send more than 50 swclktck cycles with swdiotms = 1 13.7.4 fpb (flash patch breakpoint) the fpb: ? implements hardware breakpoints ? patches code and data from code space to system space. the fpb unit contains: ? two literal comparators for matching against liter al loads from code space, and remapping to a corresponding area in system space. ? six instruction comparators for matching against inst ruction fetches from code space and remapping to a corresponding area in system space. ? alternatively, comparators can also be configured to generate a breakpoint instruction to the processor core on a match. table 13-2. swj-dp pin list pin name jtag port seri al wire debug port tms/swdio tms swdio tck/swclk tck swclk tdi tdi - tdo/traceswo tdo traceswo (optional: trace)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 316 13.7.5 dwt (data watchpoint and trace) the dwt contains four comparators which can be configured to generate the following: ? pc sampling packets at set intervals ? pc or data watchpoint packets ? watchpoint event to halt core the dwt contains counters for the items that follow: ? clock cycle (cyccnt) ? folded instructions ? load store unit (lsu) operations ? sleep cycles ? cpi (all instruction cycles except for the first cycle) ? interrupt overhead 13.7.6 itm (instrumentation trace macrocell) the itm is an application driven trace source that supports printf style debugging to trace operating system (os) and application events , and emits diagnostic system information. the itm emits trace information as packets which can be generated by three different sources with several priority levels: ? software trace : software can write directly to itm stimulus regi sters. this can be done thanks to the ?printf? function. for more information, refer to section 13.7.6.1 ?how to configure the itm? . ? hardware trace : the itm emits packets generated by the dwt. ? time stamping : timestamps are emitted relative to packets. the itm contains a 21-bit counter to generate the timestamp. 13.7.6.1 how to configure the itm the following example describes how to output trace data in asynchronous trace mode. ? configure the tpiu for asynchronous trace mode (refer to section 13.7.6.3 ?how to configure the tpiu? ) ? enable the write accesses into the itm registers by writing ?0xc5acce55? into the lock access register (address: 0xe0000fb0) ? write 0x00010015 into the trace control register: ? enable itm ? enable synchronization packets ? enable swo behavior ? fix the atb id to 1 ? write 0x1 into the trace enable register: ? enable the stimulus port 0 ? write 0x1 into the trace privilege register: ? stimulus port 0 only accessed in privileged mode (clearing a bit in this register will result in the corresponding stimulus port being accessible in user mode.) ? write into the stimulus port 0 regist er: tpiu (trace po rt interface unit) the tpiu acts as a bridge between the on-chip tr ace data and the instruction trace macrocell (itm). the tpiu formats and transmits trace data off-ch ip at frequencies asynchronous to the core.
317 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 13.7.6.2 asynchronous mode the tpiu is configured in asynchronous mode, trace data are output using the single traceswo pin. the traceswo signal is multiplexed with the tdo signal of the jtag debug port. as a consequence, asynchronous trace mode is only available when the serial wire debug mode is selected since tdo signal is used in jtag debug mode. two encoding formats are available for the single pin output: ? manchester encoded stream. this is the reset value. ? nrz_based uart byte structure 13.7.6.3 how to configure the tpiu this example only concerns the asynchronous trace mode. ? set the trcena bit to 1 into the debug exception and monitor register (0xe000edfc) to enable the use of trace and debug blocks. ? write 0x2 into the selected pin protocol register ? select the serial wire output ? nrz ? write 0x100 into the formatter and flush control register ? set the suitable clock prescaler value into the async clock prescaler register to scale the baud rate of the asynchronous output (this can be done automatically by the debugging tool). 13.7.7 ieee ? 1149.1 jtag boundary scan ieee 1149.1 jtag boundary scan allo ws pin-level access independent of the device packagi ng technology. ieee 1149.1 jtag boundary scan is enabled when tst is tied low, while jtagsel is high and pa7 is tied low during the power-up, and must be kept in this state during the whole boundary scan operation. the sample, extest and bypass functions ar e implemented. in swd/jtag debug mode, the arm processor re sponds with a non-jtag chip id th at identifies the proc essor. this is not i eee 1149.1 jtag-compliant. it is not possible to switch directly between jtag boun dary scan and swj debug port operations. a chip reset must be performed after jtagsel is changed. a boundary-scan descriptor language (bsdl) file is provided on atmel?s web site to set up the test. 13.7.7.1 jtag boundary-scan register the boundary-scan register (bsr) contains a number of bits which correspond to active pins and associated control signals. each sam4 input/output pin corresponds to a 3-bit register in the bsr. the output bit contains data that can be forced on the pad. the input bit facilitates the observability of data appli ed to the pad. the control bit selects the direction of the pad. for more information, refer to bdsl files available for the sam4 series.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 318 13.7.8 id code register access: read-only ? version[31:28]: pr oduct version number set to 0x0. ? part number[27:12]: product part number ? manufacturer identity[11:1] set to 0x01f. ? bit[0] required by ieee std. 1149.1. set to 0x1. 31 30 29 28 27 26 25 24 version part number 23 22 21 20 19 18 17 16 part number 15 14 13 12 11 10 9 8 part number manufacturer identity 76543210 manufacturer identity 1 chip name chip id sam4cm 0x05b34 chip name jtag id code sam4cm 0x05b3_403f
319 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 14. boot program 14.1 description the sam-ba boot program integrates an array of programs permitting download and/or upload into the different memories of the product. 14.2 hardware and software constraints ? sam-ba boot uses the first 4096 bytes of the sram fo r variables and stacks. the remaining available size can be used for user code. ? uart0 requirements: none 14.3 flow diagram the boot program implements the algorithm in figure 14-1 . figure 14-1. boot program algorithm flow diagram the sam-ba boot program uses the internal 12 mhz rc osci llator as source clock for pll. the mck runs from pll divided by 2. the core runs at 48 mhz. 14.4 device initialization initialization follows t he steps described below: 1. stack setup 2. setup the embedded flash controller 3. switch on internal 12 mhz rc oscillator 4. configure pllb to run at 48 mhz 5. configure uart0 6. disable watchdog 7. wait for a character on uart0 8. jump to sam-ba monitor (see section 14.5 ?sam-ba monitor? ) table 14-1. pins driven during boot program execution peripheral pin pio line uart0 urxd0 pb4 uart0 utxd0 pb5 device setup character # received from uart0? run sam-ba monitor ye s no
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 320 14.5 sam-ba monitor the sam-ba boot principle: once the communication interface is id entified, to run in an infinite loop waiting for different commands as shown in table 14-2 . ? mode commands: ? normal mode configures sam-ba monitor to send/receive data in binary format ? terminal mode configures sam-ba monitor to send/receive data in ascii format ? write commands: write a byte ( o ), a halfword ( h ) or a word ( w ) to the target ? address : address in hexadecimal ? value : byte, halfword or word to write in hexadecimal ? read commands: read a byte ( o ), a halfword ( h ) or a word ( w ) from the target ? address : address in hexadecimal ? output : the byte, halfword or word read in hexadecimal ? send a file ( s ): send a file to a specified address ? address : address in hexadecimal note: there is a time-out on this command which is reached when the prompt ?>? appears bef ore the end of the command execution. ? receive a file ( r ): receive data into a f ile from a specified address ? address : address in hexadecimal ? nbofbytes : number of bytes in hexadecimal to receive ? go ( g ): jump to a specified address and execute the code ? address : address to jump in hexadecimal ? get version ( v ): return the sam-ba boot version note: in terminal mode, when the requested command is perfo rmed, sam-ba monitor adds the following prompt sequence to its answer: ++'>'. table 14-2. commands available through the sam-ba boot command action argument(s) example n set normal mode no argument n # t set terminal mode no argument t # o write a byte address, value# o 200001,ca# o read a byte address,# o 200001,# h write a half word address, value# h 200002,cafe# h read a half word address,# h 200002,# w write a word address, value# w 200000,cafedeca# w read a word address,# w 200000,# s send a file address,# s 200000,# r receive a file address, nbofbytes# r 200000,1234# g go address# g 200200# v display version no argument v#
321 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 14.5.1 uart0 serial port communication is performed through the uart 0 initialized to 115200 baud, 8, n, 1. the send and receive file commands use the xmodem protocol to communicate. any terminal performing this protocol can be used to send the application file to the target. the size of the binary file to send depends on the sram size embedded in the product. in all cases, the size of the binary file must be lower than the sram size because the xmodem protocol requires some sram memory to work. see section 14.2 ?hardware and software constraints? 14.5.2 xmodem protocol the supported xmodem protocol is the 128-byte length block. this protocol uses a two-character crc-16 to guarantee detection of a maximum bit error. xmodem protocol with crc is accurate provided both sen der and receiver report a successful transmission. each block of the transfer looks like: <255-blk #><--1 28 data bytes--> where: ? = 01 hex ? = binary number, starts at 01, increments by 1, and wraps 0ffh to 00h (not to 01) ? <255-blk #> = 1?s complement of the blk#. ? = 2 bytes crc16 figure 14-2 shows a transmission using this protocol. figure 14-2. xmodem transfer example host device soh 01 fe data[128] crc crc c ack soh 02 fd data[128] crc crc ack soh 03 fc data[100] crc crc ack eot ack
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 322 14.5.3 in application programming (iap) feature the iap feature is a function located in rom that can be called by any software application. when called, this function sends the desired flash co mmand to the eefc and waits for the flash to be ready (looping while the frdy bit is not set in the eefc_fsr register). since this function is executed from rom, this allows flash programming (such as sector write) to be done by code running in flash. the iap function entry point is retrieved by reading the nmi vector in rom (0x02000008 ). this function takes one argument in paramet er: the command to be sent to the eefc. this function returns the value of the eefc_fsr register. iap software code example: (unsigned int) (*iap_function)(unsigned long); void main (void){ unsigned long flashsectornum = 200; // unsigned long flash_cmd = 0; unsigned long flash_status = 0; unsigned long efcindex = 0; // 0:eefc0, 1: eefc1 /* initialize the function pointer (retrieve function address from nmi vector) */ iap_function = ((unsigned long) (*)(unsigned long)) 0x02000008 ; /* send your data to the sector here */ /* build the command to send to eefc */ flash_cmd = (0x5a << 24) | (flashsectornum << 8) | at91c_mc_fcmd_ewp; /* call the iap function with appropriate command */ flash_status = iap_function (efcindex, flash_cmd); }
323 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 15. reset controller (rstc) 15.1 description the reset controller (rstc), based on power-on reset cell s, handles all the resets of the system without any external components. it reports which reset occurred last. the reset controller also drives independently or si multaneously the ex ternal reset and the peripheral and processor resets. 15.2 embedded characteristics ? management of all syst em resets, including ? external devices th rough the nrst pin ? processor reset and coprocessor (second processor) reset ? processor peripheral set reset and coprocessor peripheral set reset ? based on embedded power-on cell ? reset source status ? status of the last reset ? either software reset, user reset, watchdog reset ? external reset signal shaping 15.3 block diagram figure 15-1. reset controller block diagram nrst proc_nreset wd_fault periph_nreset slck reset state manager reset controller rstc_irq nrst manager exter_nreset nrst_out core_backup_reset coproc_nreset coproc_periph_nreset wdrproc user_reset vddcore_nreset
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 324 15.4 functional description 15.4.1 reset controller overview the reset controller is made up of an nrst manager and a reset state manager. it runs at slow clock and generates the following reset signals: ? proc_nreset: processor reset line (also resets the watchdog timer) ? coproc_nreset: coprocessor (second processor) reset line ? periph_nreset: affects the whole set of embedded peripherals ? coproc_periph_nreset: affects the whole set of em bedded peripherals driven by the co- processor ? nrst_out: drives the nrst pin these reset signals are asserted by the reset controll er, either on events generated by peripherals, events on nrst pin, or on software action. the reset state manager controls the generation of re set signals and provides a signal to the nrst manager when an assertion of the nrst pin is required. the nrst manager shapes the nrst assertion during a programmable time, thus controlling external device resets. the reset controller mode register (rstc_mr), used to configure the reset controlle r, is powered with vddbu, so that its configuration is sa ved as long as vddbu is on. 15.4.2 nrst manager after power-up, nrst is an output during the external reset length (erstl) time period defined in the rstc_mr. when the erstl time has elapsed, the pin behaves as an input a nd all the system is held in reset if nrst is tied to gnd by an external signal. the nrst manager samples the nrst input pin and drives this pin low when required by the reset state manager. figure 15-2 shows the block diagram of the nrst manager. figure 15-2. nrst manager 15.4.2.1 nrst signal or interrupt the nrst manager samples the nrst pin at slow clock speed. when the line is detected low, a user reset is reported to the reset state manager. however, the nrst manager can be programmed to not trigger a reset when an assertion of nrst occurs. writing a 0 to the ursten bit in the rs tc_mr disables the user reset trigger. the level of the pin nrst can be read at any time in the bit nrstl (nrst level) in the reset controller status register (rstc_sr). as soon as the nrst pin is asserted, bit ursts in the rstc_sr is set. this bit is cleared only when the rstc_sr is read. external reset timer ursts ursten erstl exter_nreset urstien rstc_mr rstc_mr rstc_mr rstc_sr nrstl nrst_out nrst rstc_irq other interrupt sources user_reset
325 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the reset controller can also be programmed to generate an interrupt instead of generating a reset. to do so, set the urstien bit in the rstc_mr. 15.4.2.2 nrst external reset control the reset state manager asserts the signal exter_nreset to assert the nrst pin. when this occurs, the ?nrst_out? signal is driven low by the nrst manager for a time pr ogrammed by field erstl in t he rstc_mr. this assertion duration, named external reset length, lasts 2 (erstl+1) slow clock cycles. this gi ves the approximate duration of an assertion between 60 s and 2 sec onds. note that erstl at 0 defines a two-cycle duration for the nrst pulse. this feature allows the rese t controller to shape the nrst pin level, and thus to guarantee that the nrst line is driven low for a time compliant with potential external devices connected on the system reset. rstc_mr is backed up, making it possible to use the erstl field to shape the system power-up reset for devices requiring a longer startup time than that of the slow clock oscillator. 15.4.3 reset states the reset state manager handles the different reset sources and generates the internal reset signals. it reports the reset status in field rsttyp of the status register (rstc_sr). the upd ate of rstc_sr.rsttyp is performed when the processor reset is released. 15.4.3.1 general reset a general reset occurs when a vddbu power-on-reset is detected, a brownout or a voltage regulation loss is detected by the supply controller. th e vddcore_nreset signal is asserted by the supply controller when a general reset occurs. all the reset signals are released and field rstc_sr.rs ttyp reports a general reset. as the rstc_mr is reset, the nrst line rises two cycles after the vddcor e_nreset, as erstl defaults at value 0x0. figure 15-3 shows how the general reset affects the reset signals. figure 15-3. general reset state slck periph_nreset proc_nreset nrst (nrst_out) external reset length = 2 cycles mck processor startup = 2 cycles vddbu_nreset any freq. rsttyp xxx 0x0 = general reset xxx
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 326 15.4.3.2 backup reset a backup reset occurs when the chip exits from backup mode. while exiting backup mode, the vddcore_nreset signal is asserted by the supply controller. field rstc_sr.rsttyp is updated to report a backup reset. 15.4.3.3 watchdog reset the watchdog reset is entered when a watchdog fault occurs. this reset lasts three slow clock cycles. when in watchdog reset, assertion of the reset si gnals depends on the wdrproc bit in the wdt_mr: ? if wdrproc = 0, the processor reset and the perip heral reset are asserted. the nrst line is also asserted, depending on how field rstc_mr.erstl is programmed. however, th e resulting low level on nrst does not result in a user reset state. ? if wdrproc = 1, only the processor reset is asserted. the watchdog timer is reset by the proc_nreset signal. as the watchdog fault always causes a processor reset if wdrsten in the wdt_mr is set, the watchdog timer is always reset after a watchdog reset, and the watchdog is enabled by default and with a period set to a maximum. when bit wdt_mr.wdrsten is reset, the watchdo g fault has no impact on the reset controller. figure 15-4. watchdog reset 15.4.3.4 software reset the reset controller offers commands to assert the di fferent reset signals. these commands are performed by writing the control register (rstc_cr) or coprocesso r mode register (rstc_cpmr) with the following bits at 1: ? rstc_cr.procrst: writing a 1 to procrst resets the processor and the watchdog timer. ? rstc_cr.perrst: writing a 1 to perrst resets all the embedded peripherals associated to processor whereas the coprocessor peripherals are not reset, incl uding the memory system, and, in particular, the remap command. the peripheral reset is generally used for debug purposes. only if wdrproc = 0 slck periph_nreset proc_nreset wd_fault nrst (nrst_out) external reset length 8 cycles (erstl=2) mck processor startup = 2 cycles any freq. rsttyp any xxx 0x2 = watchdog reset
327 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 except for debug purposes, perrst must always be used in conjunction with procrst (perrst and procrst set both at 1 simultaneously). ? rstc_cpmr.cprocen: writing a 0 to cprocen resets the coprocessor only. ? rstc_cpmr.cperen: writing a 0 to cperen resets all the embedded peripherals associated to coprocessor whereas the processor peripherals are not reset. ? rstc_cr.extrst: writing a 1 to extrst asserts low the nrst pin during a time defined by the field rstc_mr.erstl. the software reset is entered if at least one of these bits is set by the software. all these commands can be performed independen tly or simultaneously. th e software reset lasts three slow clock cycles. the internal reset signals are asserted as soon as the register write is performed. this is detected on the master clock (mck). they are released when the softwar e reset has ended, i.e., synchronously to slck. if extrst is set, the nrst_out si gnal is asserted depending on the c onfiguration of fi eld rstc_mr.erstl. however, the resulting falling edge on nr st does not lead to a user reset. if and only if the procrst bit is se t, the reset controller reports the softw are status in field rstc_sr.rsttyp. other software resets are not reported in rsttyp. as soon as a software operation is detected, the bit s rcmp (software reset command in progress) is set in the rstc_sr. srcmp is cleared at the end of the software reset. no other soft ware reset can be performed while the srcmp bit is set, and writing any value in the rstc_cr has no effect. figure 15-5. software reset 15.4.3.5 user reset the user reset is entered when a low level is detected on the nrst pin and bit ursten in the rstc_mr is at 1. the nrst input signal is resynchronized with sl ck to insure proper behavior of the system. slck periph_nreset if perrst=1 proc_nreset if procrst=1 write rstc_cr nrst (nrst_out) if extrst=1 external reset length 8 cycles (erstl=2) mck processor startup = 2 cycles any freq. rsttyp any xxx 0x3 = software reset resynch. 1 cycle srcmp in rstc_sr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 328 the user reset is entered as soon as a low level is de tected on nrst. the processor and coprocessor reset and the peripheral resets are asserted. the user reset ends when nrst rises, after a two-cy cle resynchronization time and a three-cycle processor startup. the processor clock is re-ena bled as soon as nrst is confirmed high. when the processor reset signal is released, field rstc_sr.rsttyp is load ed with the value 0x4, indicating a user reset. the nrst manager guarantees that the nrst line is asse rted for external reset length slow clock cycles, as programmed in field rstc_mr.erstl. however, if nrst does not rise after external reset length because it is driven low externally, the inte rnal reset lines remain assert ed until nrst actually rises. figure 15-6. user reset state 15.4.4 reset state priorities the reset state manager manages the priorities among the di fferent reset sources. the resets are listed in order of priority as follows: 1. general reset 2. backup reset 3. watchdog reset 4. software reset 5. user reset particular cases are listed below: ? when in user reset: ? a watchdog event is impossible because the watchdog timer is being reset by the proc_nreset signal. ? a software reset is impossible, since th e processor reset is being activated. ? when in software reset: ? a watchdog event has priority over the current state. ? the nrst has no effect. slck periph_nreset proc_nreset nrst nrst (nrst_out) >= external reset length mck processor startup = 2 cycles any freq. resynch. 2 cycles rsttyp any xxx resynch. 2 cycles 0x4 = user reset
329 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? when in watchdog reset: ? the processor reset is active and so a software reset cannot be programmed. ? a user reset cannot be entered.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 330 15.5 reset controller (rstc) user interface table 15-1. register mapping offset register name access reset 0x00 control register rstc_cr write-only ? 0x04 status register rstc_sr read-only 0x0000_0000 0x08 mode register rstc_mr read/write 0x0000 0001 0x0c coprocessor mode register rstc_cpmr read/write 0x0000_0000
331 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 15.5.1 reset controller control register name: rstc_cr address: 0x400e1400 access: write-only ? procrst: processor reset 0: no effect 1: if key is correct, resets the processor ? perrst: peripheral reset 0: no effect 1: if key is correct, resets the processor peripherals ? extrst: external reset 0: no effect 1: if key is correct, asserts the nrst pin ? key: system reset key 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????e x t r s tp e r r s t?p r o c r s t value name description 0xa5 passwd writing any other value in th is field aborts the write operation.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 332 15.5.2 reset controller status register name: rstc_sr address: 0x400e1404 access: read-only ? ursts: user reset status a high-to-low transition of the nrst pin sets the ursts bit. th is transition is also detected on the mck rising edge. if the user reset is disabled (ursten = 0 in rstc_mr) and if the interruption is enabled by the urstien bit in the rstc_mr, the ursts bit triggers an interrupt. reading the rstc_sr resets the ursts bit and clears the interrupt. 0: no high-to-low edge on nrst happened since the last read of rstc_sr. 1: at least one high-to-low transition of nrst has been detected since the last read of rstc_sr. ? rsttyp: reset type this field reports the cause of the last processor reset. reading this rstc_sr does not reset this field. ? nrstl: nrst pin level this bit registers the nrst pin level sampled on each master clock (mck) rising edge. ? srcmp: software reset command in progress when set, this bit indicates that a softwar e reset command is in progress and that no further software reset should be per- formed until the end of the current one. this bit is auto matically cleared at the end of the current software reset. 0: no software command is being performed by the reset controller. the reset controller is ready for a software command. 1: a software reset command is being performed by the reset controller. the reset controller is busy. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ??????s r c m pn r s t l 15 14 13 12 11 10 9 8 ????? r s t t y p 76543210 ???????u r s t s value name description 0 general_rst first power-up reset 1 backup_rst return from backup mode 2 wdt_rst watchdog fault occurred 3 soft_rst processor reset required by the software 4 user_rst nrst pin detected low 5? r e s e r v e d 6? r e s e r v e d 7? r e s e r v e d
333 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 15.5.3 reset controller mode register name: rstc_mr address: 0x400e1408
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 334 access: read/write this register can only be written if the wpen bit is cleared in the system controller write protection mode register (sysc_wpmr). ? ursten: user reset enable 0: the detection of a low level on the nrst pin does not generate a user reset. 1: the detection of a low level on the nrst pin triggers a user reset. ? urstien: user reset interrupt enable 0: usrts bit in rstc_sr at 1 has no effect on rstc_irq. 1: usrts bit in rstc_sr at 1 asserts rstc_irq if ursten = 0. ? erstl: external reset length this field defines the external reset length. the external reset is asserted during a time of 2 (erstl+1) slow clock cycles. this allows assertion duration to be programmed between 60 s and 2 seconds. note that synchronization cycles must also be considered when calculating the actual reset length as previously described. ? key: write access password 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???? e r s t l 76543210 ???u r s t i e n???u r s t e n value name description 0xa5 passwd writing any other value in this field aborts the write operation. always reads as 0.
335 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 15.5.4 reset controller coprocessor mode register name: rstc_cpmr address: 0x400e140c access: read/write ? cprocen: coprocessor (second processor) enable 0: if cpkey is correct, resets the coprocessor (power-on de fault value) 1: if cpkey is correc t, deasserts the reset of the co processor ? cperen: coprocessor peripheral enable 0: if cpkey is corr ect, resets the copr ocessor pe ripherals 1: if cpkey is corr ect, deasserts the re set of the coproc essor peripherals ? cpkey: coprocessor system enable key 31 30 29 28 27 26 25 24 cpkey 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? cperen ? ? ? cprocen value name description 0x5a passwd writing any other value in th is field aborts the write operation.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 336 16. real-time timer (rtt) 16.1 description the real-time timer (rtt) is built around a 32-bit counte r used to count roll-over events of the programmable 16- bit prescaler driven from the 32-khz slow clock source. it generates a periodic interrupt and/or triggers an alarm on a programmed value. the rtt can also be configured to be driven by the 1hz rtc signal, thus ta king advantage of a calibrated 1hz clock. the slow clock source can be fully disabled to reduce power consum ption when only an elapsed seconds count is required. 16.2 embedded characteristics ? 32-bit free-running counter on prescaled slow clock or rtc calibrated 1hz clock ? 16-bit configurable prescaler ? interrupt on alarm or counter increment 16.3 block diagram figure 16-1. real-time timer 16.4 functional description the programmable 16-bit prescaler value can be configured through the rtpres field in the ?real-time timer mode register? (rtt_mr). slck rtpres rttinc alms 16-bit prescaler 32-bit counter almv = crtv rtt_mr rtt_vr rtt_ar rtt_sr rttincien rtt_mr 0 10 almien rtt_int rtt_mr set set rtt_sr read rtt_sr reset reset rtt_mr reload rtt_alarm rttrst rtt_mr rttrst rtt_mr rttdis 10 rtt_mr rtc1hz rtc 1hz
337 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 configuring the rtpres field value to 0x8000 (default value) corresponds to feeding the real-time counter with a 1hz signal (if the slow cloc k is 32.768 khz). the 32-bit counter can count up to 2 32 seconds, corresponding to more than 136 years, then roll over to 0. bit rttinc in the ?real-time timer status register? (rtt_sr) is set each time there is a prescaler roll-over (see figure 16-2 ) the real-time 32-bit counter can also be supplied by t he 1hz rtc clock. this mode is interesting when the rtc 1hz is calibrated (correction field 0 in rtc_mr) in order to guaranty the synchronism between rtc and rtt counters. setting the rtc1hz bit in the rtt_mr drives the 32-bit rtt counter from the 1hz rtc clock. in this mode, the rtpres field has no effect on the 32-bit counter. the prescaler roll-over generates an increment of the real-time timer counter if rtc1hz = 0. otherwise, if rtc1hz = 1, the real-time timer coun ter is incremented every second. the rttinc bit is set independently from the 32-bit counter increment. the real-time timer can also be used as a free-running timer with a lower time-base. the best accuracy is achieved by writing rtpres to 3 in rtt_mr. programming rtpres to 1 or 2 is forbidden. if the rtt is configured to trigger an interrupt, the interrupt occurs two slow clock cycles after reading the rtt_sr. to prev ent several executions of the interrupt handler, the interrupt must be disabled in the interrupt ha ndler and re-enabled when the rtt_sr is cleared. the crtv field can be read at any time in the ?real-time timer value register? (rtt_vr). as this value can be updated asynchronously with the master cl ock, the crtv field must be read tw ice at the same value to improve accuracy of the returned value. the current value of the counter is compared with the value written in the ?real-time timer alarm register? (rtt_ar). if the counter value matches the alarm, the alms bit in the rtt_sr is set. the rtt_ar is set to its maximum value (0xffff_ffff) after a reset. the alms flag is always a source of the rtt alarm signal that may be used to exit the system from low power modes (see figure 16-1 ). the alarm interrupt must be disabled (almien must be cleared in rtt_mr) when writing a new almv value in the rtt_ar. the rttinc bit can be used to start a periodic interrupt, the period being one second when the rtpres field value = 0x8000 and the slow clock = 32.768 khz. the rttincien bit must be cleared prior to writing a new rtpres value in the rtt_mr. reading the rtt_sr automatically clears the rttinc and alms bits. writing the rttrst bit in the rtt_mr immediately reloads and restarts the clock divider with the new programmed value. this also resets the 32-bit counter. when not used, the real-time timer can be disabled in order to suppress dynamic power consumption in this module. this can be achieved by setting the rttdis bit in the rtt_mr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 338 figure 16-2. rtt counting prescaler almv almv-1 0 almv+1 0 rtpres - 1 crtv read rtt_sr alms (rtt_sr) apb interface slck rttinc (rtt_sr) almv+2 almv+3 ... apb cycle apb cycle
339 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 16.5 real-time timer (r tt) user interface table 16-1. register mapping offset register name access reset 0x00 mode register rtt_mr read/write 0x0000_8000 0x04 alarm register rtt_ar read/write 0xffff_ffff 0x08 value register rtt_vr read-only 0x0000_0000 0x0c status register rtt_sr read-only 0x0000_0000
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 340 16.5.1 real-time timer mode register name: rtt_mr address: 0x400e1430 access: read/write ? rtpres: real-time timer prescaler value defines the number of slck periods required to incremen t the real-time timer. rtpres is defined as follows: rtpres = 0: the prescaler period is equal to 2 16 * slck periods. rtpres = 1 or 2: forbidden. rtpres 0,1 or 2: the prescaler period is equal to rtpres * slck periods. note: the rttincien bit must be cleared prior to writing a new rtpres value. ? almien: alarm interrupt enable 0: the bit alms in rtt_sr has no effect on interrupt. 1: the bit alms in rtt_ sr asserts interrupt. ? rttincien: real-time timer increment interrupt enable 0: the bit rttinc in rtt_sr has no effect on interrupt. 1: the bit rttinc in r tt_sr asserts interrupt. ? rttrst: real-time timer restart 0: no effect. 1: reloads and restarts the clock divider with the new pr ogrammed value. this also resets the 32-bit counter. ? rttdis: real-time timer disable 0: the real-time timer is enabled. 1: the real-time timer is disabled (no dynamic power consumption). note: rttdis is write only. ? rtc1hz: real-time clock 1hz clock selection 0: the rtt 32-bit counter is driven by the 16-bit prescaler roll-over events. 1: the rtt 32-bit counter is driven by the 1hz rtc clock. note: rtc1hz is write only. 31 30 29 28 27 26 25 24 ???????rtc1hz 23 22 21 20 19 18 17 16 ? ? ? rttdis ? rttrst rttincien almien 15 14 13 12 11 10 9 8 rtpres 76543210 rtpres
341 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 16.5.2 real-time timer alarm register name: rtt_ar address: 0x400e1434 access: read/write ? almv: alarm value when the crtv value in rtt_vr equals the almv field, th e alms flag is set in rtt_sr. as soon as the alms flag rises, the crtv value eq uals almv+1 (refer to figure 16-2 ). note: the alarm interrupt must be disabled (almien must be cleared in rtt_mr) when writing a new almv value . 31 30 29 28 27 26 25 24 almv 23 22 21 20 19 18 17 16 almv 15 14 13 12 11 10 9 8 almv 76543210 almv
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 342 16.5.3 real-time timer value register name: rtt_vr address: 0x400e1438 access: read-only ? crtv: current real-time value returns the current value of the real-time timer. note: as crtv can be updated asynchronously, it must be read twice at the same value. 31 30 29 28 27 26 25 24 crtv 23 22 21 20 19 18 17 16 crtv 15 14 13 12 11 10 9 8 crtv 76543210 crtv
343 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 16.5.4 real-time timer status register name: rtt_sr address: 0x400e143c access: read-only ? alms: real-time alarm status 0: the real-time alarm has not occurr ed since the last read of rtt_sr. 1: the real-time alarm occurred since the last read of rtt_sr. ? rttinc: prescaler roll-over status 0: no prescaler roll-over occurred since the last read of the rtt_sr. 1: prescaler roll-over occurred since the last read of the rtt_sr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????r t t i n ca l m s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 344 17. real-time clock (rtc) 17.1 description the real-time clock (rtc) peripheral is designed for very low power consumption. for optimal functionality, the rtc requires an accurate extern al 32.768 khz clock, which can be provided by a crystal oscillator. it combines a complete time-of-day clock with alar m and a two-hundred-year gregorian or persian calendar, complemented by a programmable periodic interrupt. the alarm and calendar registers are accessed by a 32-bit data bus. the time and calendar values are coded in binary-coded decimal (bcd) format. the time format can be 24-hour mode or 12-hour mode with an am/pm indicator. updating time and calendar fields and configuring the alarm fields are performed by a parallel capture on the 32-bit data bus. an entry control is performed to avoid loading registers with incompatible bcd form at data or with an incompatible date according to the current month/year/century. a clock divider calibration circuitry can be used to compensate for crystal osc illator frequency inaccuracy. an rtc output can be programmed to generate several waveforms, including a prescaled clock derived from 32.768 khz. timestamping capability reports the firs t and last occurenc e of tamper events. 17.2 embedded characteristics ? ultra low power consumption ? full asynchronous design ? gregorian calendar up to 2099 or persian calendar ? programmable periodic interrupt ? safety/security features: ? valid time and date programmation check ? on-the-fly time and date validity check ? crystal oscillator clock calibration ? waveform generation ? tamper timestamping registers ? register write protection
345 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.3 block diagram figure 17-1. rtc block diagram 17.4 product dependencies 17.4.1 power management the real-time clock is continuously clocked at 32.768 khz. the power management controller has no effect on rtc behavior. 17.4.2 interrupt rtc interrupt line is connected on one of the internal source s of the interrupt controller. rtc interrupt requires the interrupt controller to be programmed first. 17.5 functional description the rtc provides a full binary-coded decimal (bcd) clock that includes century (19/20), year (with leap years), month, date, day, hours, minut es and seconds reported in rtc time register (rtc_timr) and rtc calendar register (rtc_calr). the valid year range is 1900 to 2099 in gregorian mode, a two-hundred-year calendar (or 1300 to 1499 in persian mode). the rtc can operate in 24-hour mode or in 12-hour mode with an am/pm indicator. corrections for leap years are included (all years divisible by 4 being leap years except 1900). this is correct up to the year 2099. the rtc can generate configurable waveforms on rtcout0 output. 17.5.1 reference clock the reference clock is the slow clock (slck). it can be driven internally or by an external 32.768 khz crystal. during low power modes of the processor, the oscillator runs and power co nsumption is critical. the crystal selection has to take into account the current consumption for power saving and the frequency drift due to temperature effect on the circuit for time accuracy. 17.5.2 timing the rtc is updated in real time at one-second intervals in normal mode for the counters of seconds, at one- minute intervals for the counter of minutes and so on. user interface 32768 divider time slow clock: slck apb date rtc interrupt entry control interrupt control clock calibration rtcout0 wave generator alarm
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 346 due to the asynchronous operation of the rtc with respect to the rest of the chip, to be certain that the value read in the rtc registers (century, year, month, date, day, hours, minutes, seconds) are valid and stable, it is necessary to read these registers twice. if the data is the same both times, then it is valid. therefore, a minimum of two and a maximum of three accesses are required. 17.5.3 alarm the rtc has five programmable fields: mo nth, date, hours, minutes and seconds. each of these fields can be enabled or disabled to match the alarm condition: ? if all the fields are enabled, an alar m flag is generated (the corresponding flag is asserted and an interrupt generated if enabled) at a given month, date, hour/minute/second. ? if only the ?seconds? field is enabled, then an alarm is generated every minute. depending on the combination of fields enabled, a large num ber of possibilities are available to the user ranging from minutes to 365/366 days. hour, minute and second matching alarm (secen, mi nen, houren) can be enabled independently of sec, min, hour fields. note: to change one of the sec, min, hour, date, month fields, it is recommended to disable the field before changing the value and then re-enable it after the change has been made. this requires up to three accesses to the rtc_timalr or rtc_calalr. the first access clears the enable corresponding to the field to change (secen, minen, houren, dateen, mthen). if the field is already cl eared, this access is not required. the second access performs the change of the value (sec, min, hour, date , month). the third access is required to re-enable the field by writing 1 in secen, minen, houren, dateen, mthen fields. 17.5.4 error checki ng when programming verification on user interface data is performed when accessing the cent ury, year, month, date, day, hours, minutes, seconds and alarms. a check is performed on illegal bcd entries such as illegal date of the month with regard to the year and century configured. if one of the time fields is not correct, the data is not lo aded into the register/counter and a flag is set in the validity register. the user can not reset this flag. it is reset as soon as an acceptable value is programmed. this avoids any further side effects in the hardware. the same procedure is followed for the alarm. the following checks are performed: 1. century (check if it is in range 19?20 or 13?14 in persian mode) 2. year (bcd entry check) 3. date (check range 01?31) 4. month (check if it is in bcd rang e 01?12, check validity regarding ?date?) 5. day (check range 1?7) 6. hour (bcd checks: in 24-hour mode, check range 00?23 and check that am/pm flag is not set if rtc is set in 24-hour mode; in 12-hour mode check range 01?12) 7. minute (check bcd and range 00?59) 8. second (check bcd and range 00?59) note: if the 12-hour mode is selected by means of the rtc_mr, a 12-hour value can be programmed and the returned value on rtc_timr will be the corresponding 24-hour value. the entry control ch ecks the value of the am/pm indicator (bit 22 of rtc_timr) to determine the range to be checked. 17.5.5 rtc internal free running counter error checking to improve the reliability and security of the rtc, a permanent check is performed on the internal free running counters to report non-bcd or invalid date/time values.
347 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 an error is reported by tderr bit in the status register (rtc_sr) if an incorrect value has been detected. the flag can be cleared by setting the tderrclr bit in the status clear command register (rtc_sccr). anyway the tderr error flag will be set again if the sour ce of the error has not been cleared before clearing the tderr flag. the clearing of the source of such error can be done either by reprogramming a correct value on rtc_calr and/or rtc_timr. the rtc internal free running counters may automatically clear the source of tderr due to their roll-over (i.e., every 10 seconds for seconds[3:0] field in rtc_timr). in this case the tderr is held high until a clear command is asserted by tderrclr bit in rtc_sccr. 17.5.6 updating time/calendar to update any of the time/calendar fields, the user must first stop the rtc by setting the corresponding field in the control register (rtc_cr). bit updtim must be set to update time fields (hour, minute, second) and bit updcal must be set to update calendar fields (century, year, month, date, day). the ackupd bit is automatically set within a second af ter setting the updtim and/or updcal bit (meaning one second is the maximum duration of the po lling or wait for in terrupt period). once ackupd is set, it is mandatory to clear this flag by writing the corresponding bit in th e rtc_sccr, after which the user can write to the time register, the calendar register, or both. once the update is fi nished, the user must reset (0) up dtim and/or updcal in the rtc_cr. when entering programming mode of the calendar fields , the time fields remain enabled. when entering the programming mode of the time fields, both time and calendar fields are stopped. this is due to the location of the calendar logic circuity (downstream fo r low-power considerations). it is highly recommended to prepare all the fields to be updated before entering programming mode. in successive update operations, the user must wait at least one second after resetting the updtim/updcal bit in the rtc_cr before setting these bits again. this is done by waiting for the sec flag in the rtc_sr be fore setting updtim/updcal bit. after resetting updtim/updcal, the sec flag must also be cleared.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 348 figure 17-2. update sequence prepare time or calendar fields set updtim and/or updcal bit(s) in rtc_cr read rtc_sr ackupd = 1 ? clear ackupd bit in rtc_sccr update time and/or calendar values in rtc_timr/rtc_calr clear updtim and/or updcal bit in rtc_cr no yes begin end polling or irq (if enabled)
349 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.5.7 rtc accurate clock calibration the crystal oscillator that drives the rt c may not be as accurate as expected mainly due to te mperature variation. the rtc is equipped with circuitry able to correct slow clock crystal drift. to compensate for possible temperature variations over time, this accurate clock calibration circuitry can be programmed on-the-fly and also programmed during app lication manufacturing, in order to correct the crystal frequency accuracy at room temperature (20?25c). the typi cal clock drift range at room temperature is 20 ppm. in the device operating temperature range, the 32.768 khz crystal oscillator clock inaccuracy can be up to -200 ppm. the rtc clock calibration circuitry allows positive or negative correction in a range of 1.5 ppm to 1950 ppm. after correction, the remaining cr ystal drift is as follows: ? below 1 ppm, for an initial crystal drift between 1.5 ppm up to 90 ppm ? below 2 ppm, for an initial crystal drift between 90 ppm up to 130 ppm ? below 5 ppm, for an initial crystal drift between 130 ppm up to 200 ppm the calibration circuitry acts by slightly modifying the 1 hz clock period from time to time. when the period is modified, depending on the sign of the correction, the 1 hz clock period increases or reduces by around 4 ms. according to the correction, negppm and highppm values conf igured in the rtc mode register (rtc_mr), the period interval betwee n two correction events differs. the inaccuracy of a crystal oscillator at typical room te mperature (20 ppm at 20?25 c) can be compensated if a reference clock/signal is used to measure such inaccuracy. this kind of calibration operation can be set up during the final product manufacturing by means of measurement equipment embedding such a reference clock. the correction of value must be programmed into the (rtc_mr) , and this value is kept as long as the circuitry is powered (backup area). removing the backup power supply cancels this calibration. this room temperature calibration can be further processed by means of th e networking capability of the target application. to ease the comparison of the inherent crystal accuracy with the reference clock/sig nal during manufacturing, an internal prescaled 32.768 khz clock derivative signal can be assigned to dr ive rtc output. to accommodate the measure, several clock frequencies can be selected among 1 hz, 32 hz, 64 hz, 512 hz. the clock calibration correction drives the internal rtc counters but can also be observed in the rtc output when one of the following three frequencies 1 hz, 32 hz or 64 hz is configured. the correction is not visible in the rtc output if 512 hz frequency is configured. in any event, this adjustment does not ta ke into account the temperature variation. the frequency drift (up to -200 ppm) due to temperature variation can be compensated using a reference time if the application can access such a reference. if a refe rence time cannot be used, a temperature sensor can be placed close to the crystal oscillator in order to get the oper ating temperature of the crystal oscillator. once obtained, the temperature may be converted using a lookup table (describing the accuracy/temperature curve of the crystal oscillator used) and rtc_mr configured accordingly. the calibration can be performed on-t he-fly. this adjustment method is not based on a measurement of t he crystal frequency/drift and therefore can be improved by means of the networking capab ility of the tar get application. if no crystal frequency adjustment has been done during manufa cturing, it is still poss ible to do it. in the case where a reference time of the day can be obtained through lan/wan network, it is possi ble to calculate the drift of the application crystal oscillator by comparing the values read on rtc time register (rtc_timr) and programming the highppm and correction fields on rtc_mr according to the difference measured between the reference time and those of rtc_timr. 17.5.8 waveform generation waveforms can be generated by the rtc in order to take advantage of the rtc inherent prescalers while the rtc is the only powered circuitry (low power mode of operation, backup mode) or in any active modes. going into backup or low power operating modes does not affect the waveform generation outputs.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 350 the rtc output (rtcout0) has a source driver selected among seven possibilities. the first selection choice sticks the asso ciated output at 0 (this is the reset va lue and it can be used at any time to disable the waveform generation). selection choices 1 to 4 re spectively select 1 hz, 32 hz, 64 hz and 512 hz. 32 hz or 64 hz can drive, for example, a tn lcd bac kplane signal while 1 hz can be used to drive a blinking character like ?:? for basic time di splay (hour, minute) on tn lcds. selection choice 5 provides a toggling signal when the rtc alarm is reached. selection choice 6 provides a copy of the alarm flag, so the associated output is set high (logical 1) when an alarm occurs and immediately cleared when software clears the alarm interrupt source. selection choice 7 provides a 1 hz periodic high pulse of 15 s duration that can be used to drive external devices for power consumption reduction or any other purpose. pio line associated to rtc output is automatically selecting these waveforms as soon as rtc_mr corresponding fields out0 differ from 0. figure 17-3. waveform generation rtcout0 ?0? 1 hz 32 hz 64 hz 512 hz toggle_alarm flag_alarm pulse 0 1 2 3 4 5 6 7 rtc_mr(out0) flag_alarm alarm match event 1 rtc_sccr(alrclr) alarm match event 2 rtc_sccr(alrclr) toggle_alarm pulse tperiod tperiod thigh
351 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.5.9 tamper timestamping as soon as a tamper is detected, the tamper counter is incremented and the rtc stores the time of the day, the date and the source of the tamper event in registers located in the backup ar ea. up to two tamper events can be stored. the tamper counter saturates at 15. once this limit is reached, the exact number of tamper occurrence since the last read of stamping registers cannot be known. the first set of timestamping registers (rtc_tstr0, rtc_tsdr0, rtc_tssr0) cannot be overwritten, so once they have been written all data are stored until the regist ers are reset.therefore these registers are storing the first tamper occurrence after a read. the second set of timestamping registers (rtc_tstr1, rtc_tsdr1, rtc_tssr1) are overwritten each time a tamper event is detected. this implies that the date and the time data of the first and the second stamping registers may be equal. this occurs when the tamper counter value carried on field tevcnt in rtc_tstr0 equals to 1. thus this second set of registers allows to store the last occurrence of tamper before a read. reading a set of timestamping register requires three acce sses, one for the time of th e day, one for the date and one for the tamper source. reading the third part (rtc_tssr0/1) of a timestamping registers set clears the whole content of the registers (time, date and tamper source) and makes it available to store a new event.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 352 17.6 real-time clock (rtc) user interface note: if an offset is not listed in the table it must be considered as reserved. table 17-1. register mapping offset register name access reset 0x00 control register rtc_cr read/write 0x0 0x04 mode register rtc_mr read/write 0x0 0x08 time register rtc_timr read/write 0x0 0x0c calendar register rtc_calr read/write 0x01e111220 0x10 time alarm register rtc_timalr read/write 0x0 0x14 calendar alarm register rtc_calalr read/write 0x01010000 0x18 status register rtc_sr read-only 0x0 0x1c status clear command r egister rtc_sccr write-only ? 0x20 interrupt enable register rtc_ier write-only ? 0x24 interrupt disable register rtc_idr write-only ? 0x28 interrupt mask register rtc_imr read-only 0x0 0x2c valid entry register rtc_ver read-only 0x0 0xb0 timestamp time register 0 rtc_tstr0 read-only 0x0 0xb4 timestamp date register 0 rtc_tsdr0 read-only 0x0 0xb8 timestamp source register 0 rtc_tssr0 read-only 0x0 0xbc timestamp time register 1 rtc_tstr1 read-only 0x0 0xc0 timestamp date register 1 rtc_tsdr1 read-only 0x0 0xc4 timestamp source register 1 rtc_tssr1 read-only 0x0 0xc8 reserved ? ? ? 0xd0 reserved ? ? ? 0xd4?0xe0 reserved ? ? ? 0xe4 write protection mode register rtc_wpmr read/write 0x00000000 0xe8?0xf8 reserved ? ? ? 0xfc reserved ? ? ?
353 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.1 rtc control register name: rtc_cr address: 0x400e1460 access: read/write this register can only be written if the wpen bit is cleared in the rtc write protection mode register . ? updtim: update request time register 0: no effect. 1: stops the rtc time counting. time counting consists of second, minute and hour counters. time counters can be programmed once this bit is set and acknowledged by the bit ackupd of the rtc_sr. ? updcal: update reque st calendar register 0: no effect. 1: stops the rtc calendar counting. calendar counting consists of day, da te, month, year and century counters. calendar counters can be programmed once this bit is set and acknowledged by the bit ackupd of the rtc_sr. ? timevsel: time event selection the event that generates the flag timev in rtc_sr depends on the value of timevsel. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ?????? c a l e v s e l 15 14 13 12 11 10 9 8 ?????? t i m evsel 76543210 ??????u p d c a lu p d t i m value name description 0 minute minute change 1 hour hour change 2 midnight every day at midnight 3 noon every day at noon
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 354 ? calevsel: calendar event selection the event that generates the flag calev in rtc_sr depen ds on the value of calevsel value name description 0 week week change (every monday at time 00:00:00) 1 month month change (every 01 of each month at time 00:00:00) 2 year year change (every j anuary 1 at time 00:00:00)
355 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.2 rtc mode register name: rtc_mr address: 0x400e1464 access: read/write this register can only be written if the wpen bit is cleared in the rtc write protection mode register . ? hrmod: 12-/24-hour mode 0: 24-hour mode is selected. 1: 12-hour mode is selected. ? persian: persian calendar 0: gregorian calendar. 1: persian calendar. ? negppm: negative ppm correction 0: positive correction (the divider will be slightly hi gher than 32768). 1: negative correction (the divide r will be slightly lower than 32768). refer to correction and highppm field descriptions. note: negppm must be cleared to corre ct a crystal slower than 32.768 khz. ? correction: slow clock correction 0: no correction 1?127: the slow clock will be corr ected according to th e formula given in highppm description. ? highppm: high ppm correction 0: lower range ppm correction with accurate correction. 1: higher range ppm correction with accurate correction. if the absolute value of the correction to be applied is lo wer than 30 ppm, it is recommended to clear highppm. highppm set to 1 is recommended for 30 ppm correction and above. formula: if highppm = 0, then the clock frequency correction range is from 1.5 ppm up to 98 ppm. the rtc accuracy is less than 1 ppm for a range correction from 1.5 ppm up to 30 ppm. the correction field must be programmed according to the required correction in ppm; the formula is as follows: 31 30 29 28 27 26 25 24 ? ? tperiod ? thigh 23 22 21 20 19 18 17 16 ????? o u t 0 15 14 13 12 11 10 9 8 highppm correction 76543210 ? ? ? negppm ? ? persian hrmod correction 3906 20 ppm ---------------------- - 1 ? =
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 356 the value obtained must be rounded to the nearest in teger prior to being progra mmed into correction field. if highppm = 1, then the clock frequency correction range is from 30.5 ppm up to 1950 ppm. the rtc accuracy is less than 1 ppm for a range correction from 30.5 ppm up to 90 ppm. the correction field must be programmed according to the required correction in ppm; the formula is as follows: the value obtained must be rounded to the nearest integer prior to be programmed into correction field. if negppm is set to 1, the ppm correction is negative (used to correct crystal that are faster than the nominal 32.768 khz). ? out0: rtcout0 outputsource selection ? thigh: high duration of the output pulse ? tperiod: period of the output pulse value name description 0 no_wave no wavefo rm, stuck at ?0? 1 freq1hz 1 hz square wave 2 freq32hz 32 hz square wave 3 freq64hz 64 hz square wave 4 freq512hz 512 hz square wave 5 alarm_toggle output toggles when alarm flag rises 6 alarm_flag output is a copy of the alarm flag 7 prog_pulse duty cycle programmable pulse value name description 0 h_31ms 31.2 ms 1 h_16ms 15.6 ms 2 h_4ms 3.91 ms 3 h_976us 976 s 4 h_488us 488 s 5 h_122us 122 s 6 h_30us 30.5 s 7 h_15us 15.2 s value name description 0 p_1s 1 second 1 p_500ms 500 ms 2 p_250ms 250 ms 3 p_125ms 125 ms correction 3906 ppm ----------- - 1 ?=
357 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.3 rtc time register name: rtc_timr address: 0x400e1468 access: read/write ? sec: current second the range that can be set is 0?59 (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? min: current minute the range that can be set is 0?59 (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? hour: current hour the range that can be set is 1?12 (bcd) in 12-hour mode or 0?23 (bcd) in 24-hour mode. ? ampm: ante meridiem post meridiem indicator this bit is the am/pm indicator in 12-hour mode. 0: am. 1: pm. all non-significant bits read zero. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ?a m p m h o u r 15 14 13 12 11 10 9 8 ?m i n 76543210 ? sec
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 358 17.6.4 rtc calendar register name: rtc_calr address: 0x400e146c access: read/write ? cent: current century the range that can be set is 19?20 (gregorian) or 13?14 (persian) (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? year: current year the range that can be set is 00?99 (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? month: current month the range that can be set is 01?12 (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? day: current day in current week the range that can be set is 1?7 (bcd). the coding of the number (which number represents which day) is user-defined as it has no effect on the date counter. ? date: current day in current month the range that can be set is 01?31 (bcd). the lowest four bits encode the units. the higher bits encode the tens. all non-significant bits read zero. 31 30 29 28 27 26 25 24 ?? d a t e 23 22 21 20 19 18 17 16 day month 15 14 13 12 11 10 9 8 year 76543210 ?c e n t
359 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.5 rtc time alarm register name: rtc_timalr address: 0x400e1470 access: read/write this register can only be written if the wpen bit is cleared in the rtc write protection mode register . note: to change one of the sec, min, hour fields, it is recommend ed to disable the field before changing the value and then re- enable it after the change has been made. this requires up to three accesses to the rtc_timalr. the first access clears the enable corresponding to the field to change (secen, minen, ho uren). if the field is already cleared, this access is not required. the second access performs the change of the value (sec, min, hour). the third access is required to re-enable the field by writing 1 in secen, minen, houren fields. ? sec: second alarm this field is the alarm field corresp onding to the bcd-coded second counter. ? secen: second alarm enable 0: the second-matching alarm is disabled. 1: the second-matching alarm is enabled. ? min: minute alarm this field is the alarm field corresp onding to the bcd-coded minute counter. ? minen: minute alarm enable 0: the minute-matching alarm is disabled. 1: the minute-matching alarm is enabled. ? hour: hour alarm this field is the alarm field corresp onding to the bcd-coded hour counter. ? ampm: am/pm indicator this field is the alarm field corresp onding to the bcd-coded hour counter. ? houren: hour alarm enable 0: the hour-matching alarm is disabled. 1: the hour-matching alarm is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 houren ampm hour 15 14 13 12 11 10 9 8 minen min 76543210 secen sec
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 360 17.6.6 rtc calendar alarm register name: rtc_calalr address: 0x400e1474 access: read/write this register can only be written if the wpen bit is cleared in the rtc write protection mode register . note: to change one of the date, month fields, it is recommended to disable the field before changing the value and then re-enab le it after the change has been made. this requires up to three accesses to the rtc_calalr. the first access clears the enable corresponding to the field to change (dateen, mthen). if the field is already cleared, this access is not required. the second access performs the change of the value (date, month). the thir d access is required to re-enable the field by writing 1 in dateen, mthen fields. ? month: month alarm this field is the alarm field corresp onding to the bcd-c oded month counter. ? mthen: month alarm enable 0: the month-matching alarm is disabled. 1: the month-matching alarm is enabled. ?date: date alarm this field is the alarm field corresp onding to the bcd-coded date counter. ? dateen: date alarm enable 0: the date-matching alarm is disabled. 1: the date-matching alarm is enabled. 31 30 29 28 27 26 25 24 dateen ? date 23 22 21 20 19 18 17 16 mthen ? ? month 15 14 13 12 11 10 9 8 ???????? 76543210 ????????
361 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.7 rtc status register name: rtc_sr address: 0x400e1478 access: read-only ? ackupd: acknowledge for update ? alarm: alarm flag ? sec: second event ? timev: time event note: the time event is se lected in the timevsel field in the control register (rtc_cr) and ca n be any one of the following even ts: minute change, hour change, noon, midnight (day change). ? calev: calendar event note: the calendar even t is selected in the calevsel field in the control register (rtc_cr) and can be any one of the following events: week change, month change and year change. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tderr calev timev sec alarm ackupd value name description 0 freerun time and calendar registers cannot be updated. 1 update time and calendar registers can be updated. value name description 0 no_alarmevent no alarm matc hing condition occurred. 1 alarmevent an alarm matching condition has occurred. value name description 0 no_secevent no second event has occurred since the last clear. 1 secevent at least one second event ha s occurred since the last clear. value name description 0 no_timevent no time event has occurred since the last clear. 1 timevent at least one time event ha s occurred since the last clear. value name description 0 no_calevent no calendar event has occurred since the last clear. 1 calevent at least one calendar event has occurred since the last clear.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 362 ? tderr: time and/or date free running error value name description 0 correct the internal free running counters are carrying va lid values since the la st read of the status register (rtc_sr). 1 err_timedate the internal free running counters have been corrupted (invalid date or time, non-bcd values) since the last read and/or they are still invalid.
363 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.8 rtc status clear command register name: rtc_sccr address: 0x400e147c access: write-only ? ackclr: acknowledge clear 0: no effect. 1: clears corresponding status flag in the status register (rtc_sr). ? alrclr: alarm clear 0: no effect. 1: clears corresponding status flag in the status register (rtc_sr). ? secclr: second clear 0: no effect. 1: clears corresponding status flag in the status register (rtc_sr). ? timclr: time clear 0: no effect. 1: clears corresponding status flag in the status register (rtc_sr). ? calclr: calendar clear 0: no effect. 1: clears corresponding status flag in the status register (rtc_sr). ? tderrclr: time and/or date free running error clear 0: no effect. 1: clears corresponding status flag in the status register (rtc_sr). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tderrclr calclr timclr secclr alrclr ackclr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 364 17.6.9 rtc interrupt enable register name: rtc_ier address: 0x400e1480 access: write-only ? acken: acknowledge update interrupt enable 0: no effect. 1: the acknowledge for update interrupt is enabled. ? alren: alarm interrupt enable 0: no effect. 1: the alarm interrupt is enabled. ? secen: second event interrupt enable 0: no effect. 1: the second periodic interrupt is enabled. ? timen: time event interrupt enable 0: no effect. 1: the selected time event interrupt is enabled. ? calen: calendar ev ent interrupt enable 0: no effect. 1: the selected calendar event interrupt is enabled. ? tderren: time and/or date error interrupt enable 0: no effect. 1: the time and date error interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tderren calen timen secen alren acken
365 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.10 rtc interrupt disable register name: rtc_idr address: 0x400e1484 access: write-only ? ackdis: acknowledge update interrupt disable 0: no effect. 1: the acknowledge for update interrupt is disabled. ? alrdis: alarm interrupt disable 0: no effect. 1: the alarm interrupt is disabled. ? secdis: second event interrupt disable 0: no effect. 1: the second periodic interrupt is disabled. ? timdis: time event interrupt disable 0: no effect. 1: the selected time event interrupt is disabled. ? caldis: calendar ev ent interrupt disable 0: no effect. 1: the selected calendar event interrupt is disabled. ? tderrdis: time and/or da te error interrupt disable 0: no effect. ? 1: the time and date error interrupt is disabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tderrdis caldis timdis secdis alrdis ackdis
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 366 17.6.11 rtc interrupt mask register name: rtc_imr address: 0x400e1488 access: read-only ? ack: acknowledge update interrupt mask 0: the acknowledge for update interrupt is disabled. 1: the acknowledge for update interrupt is enabled. ? alr: alarm interrupt mask 0: the alarm interrupt is disabled. 1: the alarm interrupt is enabled. ? sec: second event interrupt mask 0: the second periodic interrupt is disabled. 1: the second periodic interrupt is enabled. ? tim: time event interrupt mask 0: the selected time event interrupt is disabled. 1: the selected time event interrupt is enabled. ? cal: calendar event interrupt mask 0: the selected calendar event interrupt is disabled. 1: the selected calendar event interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? cal tim sec alr ack
367 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.12 rtc valid entry register name: rtc_ver address: 0x400e148c access: read-only ? nvtim: non-valid time 0: no invalid data has been detected in rtc_timr (time register). 1: rtc_timr has contained invalid data since it was last programmed. ? nvcal: non-valid calendar 0: no invalid data has been detected in rtc_calr (calendar register). 1: rtc_calr has contained invalid data since it was last programmed. ? nvtimalr: non-valid time alarm 0: no invalid data has been detected in rtc_timalr (time alarm register). 1: rtc_timalr has contained invali d data since it was last programmed. ? nvcalalr: non-valid calendar alarm 0: no invalid data has been detected in rtc_calalr (calendar alarm register). 1: rtc_calalr has contained invalid data since it was last programmed. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????n v c a l a l rn v t i m a l rn v c a ln v t i m
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 368 17.6.13 rtc timestamp time register 0 name: rtc_tstr0 address: 0x400e1510 access: read-only ? sec: seconds of the tamper ? min: minutes of the tamper ? hour: hours of the tamper ? ampm: am/pm indicator of the tamper ? tevcnt: tamper events counter each time a tamper event occurs, this coun ter is incremented. this counter saturates at 15. once this va lue is reached, it is no more possible to know the exact number of tamper events. if this field is not null, this implies that at least one tamper event occurs since la st register reset and that the values sto red in timestamping registers are valid. ? backup: system mode of the tamper 0: the state of the system is different from backup mode when the tamper event occurs. 1: the system is in backup mode when the tamper event occurs. this register is cleared by reading rtc_tssr0. all non-significant bits read zero. 31 30 29 28 27 26 25 24 backup ? ? ? tevcnt 23 22 21 20 19 18 17 16 ?a m p m h o u r 15 14 13 12 11 10 9 8 ?m i n 76543210 ? sec
369 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.14 rtc timestamp time register 1 name: rtc_tstr1 address: 0x400e151c access: read-only ? sec: seconds of the tamper ? min: minutes of the tamper ? hour: hours of the tamper ? ampm: am/pm indicator of the tamper this register is cleared by reading rtc_tssr1. ? backup: system mode of the tamper 0: the state of the system is different from backup mode when the tamper event occurs. 1: the system is in backup mode when the tamper event occurs. all non-significant bits read zero. 31 30 29 28 27 26 25 24 b a c k u p??????? 23 22 21 20 19 18 17 16 ?a m p m h o u r 15 14 13 12 11 10 9 8 ?m i n 76543210 ? sec
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 370 17.6.15 rtc timestamp date register name: rtc_tsdrx address: 0x400e1514 [0], 0x400e1520 [1] access: read-only ? cent: century of the tamper ? year: year of the tamper ? month: month of the tamper ? day: day of the tamper ? date: date of the tamper the fields contains the date and the source of a tamper occurrence if the tevcnt is not null. this register is cleared by reading rtc_tssr. all non-significant bits read zero. 31 30 29 28 27 26 25 24 ?? d a t e 23 22 21 20 19 18 17 16 day month 15 14 13 12 11 10 9 8 year 76543210 ?c e n t
371 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.6.16 rtc timestamp source register name: rtc_tssrx address: 0x400e1518 [0], 0x400e1524 [1] access: read-only ? tsrc: tamper source this field contains the tamper source. it is valid only if the tevcnt is not null. this register is cleared after read and the read access also performs a clear on rtc_tstr and rtc_tsdr. all non-significant bits read zero. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????? t s r c
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 372 17.6.17 rtc write protection mode register name: rtc_wpmr address: 0x400e1544 access: read/write ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x525443 (?rtc? in ascii). 1: enables the write protecti on if wpkey corres ponds to 0x525443 (?rtc? in ascii). the following registers can be write-protected: ? rtc mode register ? rtc time alarm register ? rtc calendar alarm register ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x525443 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
373 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 18. watchdog timer (wdt) 18.1 description the watchdog timer (wdt) is used to prevent system lock-up if the software becomes trapped in a deadlock. it features a 12-bit down counter that allows a watchdog period of up to 16 seconds (slow clock around 32 khz). it can generate a general reset or a processor reset only. in addition, it can be stopped while the processor is in debug mode or idle mode. 18.2 embedded characteristics ? 12-bit key-protected programmable counter ? watchdog clock is independent from processor clock ? provides reset or interrupt signals to the system ? counter may be stopped while the processor is in debug state or in idle mode
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 374 18.3 block diagram figure 18-1. watchdog timer block diagram = 0 10 set reset read wdt_sr or reset wdt_fault (to reset controller) set reset wdfien wdt_int wdt_mr slck 1/128 12-bit down counter current value wdd wdt_mr <= wdd wdv wdrstt wdt_mr wdt_cr reload wdunf wderr reload write wdt_mr wdt_mr wdrsten
375 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 18.4 functional description the watchdog timer is used to prevent system lock-up if the software becomes trapped in a deadlock. it is supplied with vddcore. it restarts with initial values on processor reset. the watchdog is built around a 12-bit down counter, which is loaded with the value defined in the field wdv of the mode register (wdt_mr). the watchd og timer uses the slow clock divid ed by 128 to establish the maximum watchdog period to be 16 seconds (with a typical slow clock of 32.768 khz). after a processor reset, the value of wdv is 0xfff, co rresponding to the maximum value of the counter with the external reset generation enabled (field wdrsten at 1 a fter a backup reset). this means that a default watchdog is running at reset, i.e., at power-up. the user must eith er disable it (by setting t he wddis bit in wdt_mr) if he does not expect to use it or must reprogram it to meet the maximum watchdog period the application requires. if the watchdog is restarted by writing into the control register (wdt_cr), wdt_mr must not be programmed during a period of time of three slow clock periods following the wdt_cr write access. in any case, programming a new value in wdt_mr automatically initiates a rest art instruction. wdt_mr can be written only once . only a processor rese t resets it. writing wdt_mr reloads the timer with the newly programmed mode parameters. in normal operation, the user reloads the watchdog at regular intervals before the timer underflow occurs, by writing wdt_cr with the bit wdrstt to 1. the watchdog counter is then immediately reloaded from wdt_mr and restarted, and the slow clock 128 divider is reset and restarted. wdt_cr is writ e-protected. as a result, writing wdt_cr without the correct hard-coded key has no effect. if an underflow does occur, the ?wdt_fault? signal to the reset controlle r is asserted if the bit wdrsten is set in wdt_mr. moreover, the bit wdunf is set in the status register (wdt_sr). to prevent a software deadlock that continuously triggers the watchdog, the reload of the watchdog must occur while the watchdog counter is within a window bet ween 0 and wdd, wdd is defined in wdt_mr. any attempt to restart the watchdog while the watchdog counter is between wdv and wdd results in a watchdog error, even if the watchdog is disabled. the bit wderr is updated in wdt_sr and the ?wdt_fault? signal to the reset controller is asserted. note that this feature can be disabled by programming a wdd value greater than or equal to the wdv value. in such a configuration, restarting the watchdog timer is permitted in the whole range [0; wdv] and does not generate an error. this is the default configurat ion on reset (the wdd and wdv values are equal). the status bits wdunf (watchdog underflow) and wderr (watchdog error) trigger an interrupt, provided the bit wdfien is set in wdt_mr. the signal ?wdt_fault? to the reset controller causes a watchdog reset if the wdrsten bit is set as already explained in the reset controller document ation. in this case, the processor and the watchdog timer are reset, and the wderr and wdunf flags are reset. if a reset is generated or if wdt_sr is read, the status bits are reset, the interrupt is cleared, and the ?wdt_fault? signal to the reset controller is deasserted. writing wdt_mr reloads and restarts the down counter. while the processor is in debug state or in idle mode, the counter may be stopped depending on the value programmed for the bits wdidlehlt and wddbghlt in wdt_mr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 376 figure 18-2. watchdog behavior 0 wdv wdd wdt_cr.wdrstt=1 w atchdog f ault norm al beha vior w atchdog error w a tchdog underflow fff if wdrsten is 1 if wdrsten is 0 for bidden window permitted window
377 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 18.5 watchdog timer (wdt) user interface table 18-1. register mapping offset register name access reset 0x00 control register wdt_cr write-only ? 0x04 mode register wdt_mr read/write once 0x3fff_2fff 0x08 status register wdt_sr read-only 0x0000_0000
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 378 18.5.1 watchdog timer control register name: wdt_cr address: 0x400e1450 access: write-only ? wdrstt: watchdog restart 0: no effect. 1: restarts the watchdog if key is written to 0xa5. ? key: password. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????w d r s t t value name description 0xa5 passwd writing any other value in this field aborts the write operation.
379 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 18.5.2 watchdog timer mode register name: wdt_mr address: 0x400e1454 access: read/write once note: the first write access prevents any further modification of the value of this register. re ad accesses remain possible. note: the wdd and wdv values must not be modified within three slow clock periods following a restart of the watchdog performed by a write access in wdt_cr. any modification will cause the watchdog to trigger an end of period earlier than expected. ? wdv: watchdog counter value defines the value loaded in the 12-bit watchdog counter. ? wdfien: watchdog fault interrupt enable 0: a watchdog fault (underflow or er ror) has no effect on interrupt. 1: a watchdog fault (underflow or error) asserts interrupt. ? wdrsten: watchdog reset enable 0: a watchdog fault (underflow or erro r) has no effect on the resets. 1: a watchdog fault (underflow or error) triggers a watchdog reset. ? wdrproc: watchdog reset processor 0: if wdrsten is 1, a watchdog fault ( underflow or error) activates all resets. 1: if wdrsten is 1, a watchdog fault (under flow or error) activates the processor reset. ? wdd: watchdog delta value defines the permitted range for reloading the watchdog timer. if the watchdog timer value is less than or equal to wdd, writing wdt_cr wi th wdrstt = 1 restarts the timer. if the watchdog timer value is greater than wdd, writing wdt_cr with wdrstt = 1 causes a watchdog error. ? wddbghlt: watchdog debug halt 0: the watchdog runs when the processor is in debug state. 1: the watchdog stops when the processor is in debug state. 31 30 29 28 27 26 25 24 ? ? wdidlehlt wddbghlt wdd 23 22 21 20 19 18 17 16 wdd 15 14 13 12 11 10 9 8 wddis wdrproc wdrsten wdfien wdv 76543210 wdv
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 380 ? wdidlehlt: watchdog idle halt 0: the watchdog runs when the system is in idle mode. 1: the watchdog stops when the system is in idle state. ? wddis: watchdog disable 0: enables the watchdog timer. 1: disables the watchdog timer.
381 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 18.5.3 watchdog timer status register name: wdt_sr address: 0x400e1458 access read-only ? wdunf: watchdog underflow 0: no watchdog underflow occurred since the last read of wdt_sr. 1: at least one watchdog underflow occurred since the last read of wdt_sr. ? wderr: watchdog error 0: no watchdog error occurred si nce the last read of wdt_sr. 1: at least one watchdog error occurred since the last read of wdt_sr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????w d e r rw dunf
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 382 19. reinforced safety w atchdog timer (rswdt) 19.1 description when two watchdog timers are implemented in a device, the second one, the reinforced safety watchdog timer (rswdt), works in parallel with the watchdog timer (wdt) to reinforce safe watchdog operations. the rswdt can be used to reinforce the safety level pr ovided by the watchdog timer (wdt) in order to prevent system lock-up if the software becomes trapped in a deadlock. the rswdt works in a fully operable mode, independent of the watchdog timer. its clock source is au tomatically selected from either the slow rc oscillator clock or main rc oscillator divided cloc k to get an equivalent slow rc oscillato r clock. if the watchdog timer clock source (for example the 32 khz crystal oscillator) fails, the system lock-up is no longer monito red by the watchdog timer as the second watchd og timer, rswdt, will perform the monitori ng. thus, there is no lack of safety irrespective of the external operating conditions. this rswdt shares the same features as the wdt (i.e., a 12-bit down counter that allows a watchdog per iod of up to 16 seconds with slow cl ock at 32.768 khz). it can generate a general reset or a processor reset only. in addition, it ca n be stopped while the processor is in debug mode or idle mode. 19.2 embedded characteristics ? system safety level reinforced by means of an independent second watchdog timer ? automatically selected reliable independent clock source other than that of first watchdog timer ? windowed watchdog ? 12-bit key-protected programmable counter ? provides reset or interr upt signals to the system ? counter may be stopped while the processor is in debug state or in idle mode
383 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 19.3 block diagram figure 19-1. reinforced safety watchdog timer block diagram = 0 10 set reset read rswdt_sr or reset rswdt_fault (to reset controller) (ored with wdt_fault) set reset wdfien rswdt_int (ored with wdt_int) rswdt_mr slow rc clock 1/128 12-bit down counter current value wdd rswdt_mr <= wdd wdv wdrstt rswdt_mr rswdt_cr reload wdunf wderr reload write rswdt_mr rswdt_mr wdrsten main rc clock divider main rc frequency automatic selection [ckgr_mor.moscrcen = 0 and (wdt_mr.wddis or supc_mr.xtalsel = 1)] 1 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 384 19.4 functional description the rswdt is supplied by vddcore. the rswdt is init ialized with default values on processor reset or on power-on sequence and is disabled (its default mode) under such conditions. the rswdt assumes the wdt to be enabled. the main rc oscillator divided cl ock is selected if the main rc oscillator is already enabled by th e application (moscrcen = 1) or if the first watch dog is driven by the slow rc oscillator. the rswdt is built around a 12-bit down counter, which is loaded with a slow clock value other than that of the slow clock in the watchdog timer, defined in the wdv (watchdog counter value) field of the mode register (rswdt_mr). the rswdt uses the slow clock divided by 128 to establish the maximum watchdog period to be 16 seconds (with a typical slow clock of 32.768 khz). after a processor reset, the value of wdv is 0xfff, co rresponding to the maximum value of the counter with the external reset generation enabled (rswdt _mr.wdrsten = 1 after a backup re set). this means that a default watchdog is running at reset, i.e., at power-up. if the watchdog is restarted by writing into the cont rol register (rswdt_cr), the rswdt_mr must not be programmed during a period of time of three slow clock periods following the rswdt_cr write access. programming a new value in the rswdt_mr au tomatically initiates a restart instruction. the rswdt_mr can be written only once. only a proces sor reset resets it. writin g the rswdt_mr reloads the timer with the newly programmed mode parameters. in normal operation, the user reloads the watchdog at regular intervals before the timer underflow occurs, by setting bit rswdt_cr.wdrstt. the watc hdog counter is then immediately reloaded from the rswdt_mr and restarted, and the slow clock 128 divider is reset and re started. the rswdt_cr is wr ite-protected. as a result, writing rswdt_cr without the correct hard-coded key has no effect. if an un derflow does occur, the ?wdt_fault? signal to the reset controller is asserted if the bit rswdt_mr.wdrsten is set. moreover, the bit wdunf (watchdog underflow) is set in the status register (rswdt_sr). to prevent a software deadlock that continuously trigge rs the rswdt, the reload of the rswdt must occur while the watchdog counter is within a window between 0 and t he watchdog delta value (wdd). wdd is defined in the rswdt_mr. any attempt to restart the watchdog wh ile the watchdog counter is between the two values wdv and wdd results in a watchdog error, even if the rswdt is disabl ed. the wderr (watchdog error) bit is updated in the rswdt_sr and the ?wdt_fault? signal to the reset contro ller is asserted. note that the windowed watchdog f eature can be disabled by programming a wdd value greater than or equal to the wdv value. in such a configuration, restarting the rswdt is permitted in the whole range 0 to wdv and does not generate an error. this is the default configuration on reset (the wdd and wdv values are equal). the status bits wdunf and wderr trigger an interrupt, provided the wdfien bit is set in the rswdt_mr. the signal ?wdt_fault? to the reset controll er causes a watchdog reset if the wdrsten bit is set as explained in the ?reset controller (rstc)? section of the product datasheet. in that case, the processor and the watchdog timer are reset, and the wdunf and wderr flags are reset. if a reset is generated, or if rswdt_ sr is read, the status bits are reset, the interrupt is cleared, and the ?wdt_fault? signal to the rese t controller is deasserted. writing the rswdt_mr reloads and restarts the down counter. the rswdt is disabled after any power-on sequence. while the processor is in debug state or in idle mode, the counter may be stopped depending on the value programmed for the wdidlehlt and w ddbghlt bits in the rswdt_mr.
385 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 19-2. watchdog behavior 0 wdv wdd rswdt_cr.wdrstt = 1 watchdog fault normal behavior watchdog error watchdog underflow fff if wdrsten is 1 if wdrsten is 0 forbidden window permitted window
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 386 19.5 reinforced safety watchdog timer (rswdt) user interface table 19-1. register mapping offset register name access reset 0x00 control register rswdt_cr write-only ? 0x04 mode register rswdt_mr read-write once 0x3fff_afff 0x08 status register rswdt_sr read-only 0x0000_0000
387 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 19.5.1 reinforced safety watchdog timer control register name: rswdt_cr address: 0x400e1500 access: write-only ? wdrstt: watchdog restart 0: no effect. 1: restarts the watchdog. ? key: password 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????w d r s t t value name description 0xc4 passwd writing any other value in this field aborts the write operation.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 388 19.5.2 reinforced safety watchdog timer mode register name: rswdt_mr address: 0x400e1504 access: read-write once note: the first write access prevents any further modification of the value of this register, read accesses remain possible. note: the wdd and wdv values must not be modified within three slow clock periods following a restart of the watchdog performed by means of a write access in the rswdt_cr, else the watc hdog may trigger an end of period earlier than expected. ? wdv: watchdog counter value defines the value loaded in the 12-bit watchdog counter. ? wdfien: watchdog fault interrupt enable 0: a watchdog fault (underflow or er ror) has no effect on interrupt. 1: a watchdog fault (underflow or error) asserts interrupt. ? wdrsten: watchdog reset enable 0: a watchdog fault (underflow or erro r) has no effect on the resets. 1: a watchdog fault (underflow or error) triggers a watchdog reset. ? wdrproc: watchdog reset processor 0: if wdrsten is 1, a watchdog fault ( underflow or error) activates all resets. 1: if wdrsten is 1, a watchdog fault (under flow or error) activates the processor reset. ? wdd: watchdog delta value defines the permitted range for reloading the watchdog timer. if the watchdog timer value is less than or equal to wdd, writing rswdt_cr with wdrstt = 1 restarts the timer. if the watchdog timer value is greate r than wdd, writing rswdt_cr with wdrstt = 1 causes a watchdog error. ? wddbghlt: watchdog debug halt 0: the watchdog runs when the processor is in debug state. 1: the watchdog stops when the processor is in debug state. 31 30 29 28 27 26 25 24 ? ? wdidlehlt wddbghlt wdd 23 22 21 20 19 18 17 16 wdd 15 14 13 12 11 10 9 8 wddis wdrproc wdrsten wdfien wdv 76543210 wdv
389 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? wdidlehlt: watchdog idle halt 0: the watchdog runs when the system is in idle mode. 1: the watchdog stops when the system is in idle state. ? wddis: watchdog disable 0: enables the watchdog timer. 1: disables the watchdog timer.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 390 19.5.3 reinforced safety watchdog timer status register name: rswdt_sr address: 0x400e1508 access: read-only ? wdunf: watchdog underflow 0: no watchdog underflow occurred since the last read of rswdt_sr. 1: at least one watchdog underflow occurred since the last read of rswdt_sr. ? wderr: watchdog error 0: no watchdog error occurred si nce the last read of rswdt_sr. 1: at least one watchdog error occurr ed since the last read of rswdt_sr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????w d e r rw dunf
391 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 20. supply controller (supc) 20.1 description the supply controller (supc) cont rols the supply voltages of the sy stem and manages the backup low-power mode. in this mode, current consumption is reduced to le ss than 1 microamp (typ) for backup power retention. exit from this mode is possible on multiple wake-up sources. the supc also generates the slow clock by selecting either the low-power rc oscillator or the low-power crystal oscillator. 20.2 embedded characteristics ? manages vddcore and the backup low-power mode by controlling the embed ded voltage regulator ? manages the lcd power supply vddlcd and the ba ckup low-power mode by controlling the embedded lcd voltage regulator ? a supply monitor detection on vddio or a brownout detection on vddcore triggers a system reset ? a supply monitor detection on v ddbu_sw triggers a system reset ? generates the slow clock slck by selecting either the 32 khz low -power rc oscillato r or the 32 khz low-power crystal oscillator ? supports multiple wake-up sources fo r exit from back up low-power mode ? force wake-up pin, with programmable debouncing ? up to 13 wake-up inputs (including tamper inputs), with programmable debouncing ? real-time clock alarm ? real-time timer alarm ? supply monitor detection on vddio, with programmable scan period and voltage threshold
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 392 20.3 block diagram figure 20-1. supply controller block diagram supply monitoring vddbu vddout shdn vddlcd (in/out) core voltage regulator vroff onreg vddin lcd voltage regulator lcdmode - off (lcdoff), - active (lcdon_extvr), - hi-z (lcdon_extvr) lcdvrout vddlcd adjust backup mode used/unused automatic power switch note: tmpx signals and wkupx signals are multiplexed on the same pins (ex. tmp0/wkup0, tmp1/wkup10, etc.). this generates a wake-up event only, a tamper event only or a wake-up and a tamper event. rstc module core_backup_reset vddbu_sw reset enable disable power-on-reset vddcore brown-out detector vddcore programmable supply monitor vddio zero-power power-on-reset vddbu_sw threshold enable sampling period reset enable interrupt enable wake-up enable vddio xtalsel slck (slow clock) porcore_out bodcore_out smio_out porbusw_out smen smien smrsten smsmpl smth bupporen bodrsten boddis wake-up & tamper inputs timstpm1dis timestamp disable rtc module wkupx x:1..13 wkupdbc wkupen[1..15] programmable debouncer wake-up tmp1 lpdbc lpdbcen1 programmable lp debouncer tamper wkup0 wkupdbc wkupen0 programmable debouncer wake-up tmp0 lpdbc lpdbcen0 programmable lp debouncer tamper fwup fwupdbc fwupen programmable debouncer wake-up clear on tamper event (8/16) lpdbcclr lpdbdisclr1 general purpose backup registers x8 x8 supplied by vddcore supplied by vddbu_sw supplied by vddio supplied by vddin supply controller rtt module rtten wake-up rtcen wake-up rc osc 32khz oscbypass xtal osc 32khz slow clock control vddcore_nreset (system reset signal) i/o pin referred to vddbu i/o pin referred to vddio
393 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 20.4 supply controller functional description 20.4.1 supply controller overview the device can be divided into two power supply areas: ? the backup vddbu_sw power supply that includes the supply controller, a part of the reset controller, the slow clock switch, the general-purpose backup registers, the supply monitor and the clock which includes the real-time timer and the real-time clock. ? the core power supply that includes the other part of the reset controller, the brownout detector, the processor, the sram memory, the flash memory and the peripherals. the supc controls the core power supply and interv enes when the vddbu_sw power supply rises (when the system is starting) or when the backup low-power mode is entered. the supc also integrates the slow cl ock generator which is based on a 32 khz crystal oscillato r and an embedded 32 khz rc oscillator. the slow clock defaults to the rc oscillator, but the software can enab le the crystal oscillator and select it as th e slow clock source. the supc and the vddbu_sw power supply have a reset circuitry based on a zero-power power-on reset cell. the zero-power power-on reset allows the supc to st art properly as soon as the vddbu_sw voltage becomes valid. at start-up of the system, once th e backup voltage vddbu_sw is valid and the embedded 32 khz rc oscillator is stabilized, the supc starts up the core voltage regulator and ties the shdn pin to vddbu. once the vddcore voltage is valid, it releases the system reset signal (vddcore_nreset) to the rstc. the rstc module then releases the sub-system 0 reset signals (proc_nreset and periph_nreset). note that the sub-sytem 1 remains in reset after power-up. once the system has started, the user can program a supply monitor and/or a brownout detector. if a powerfail condition occurs on either vddio or on vddcore powe r supplies, the supc asserts the system reset signal (vddcore_nreset). this signal is releas ed when the powerfail condition is cleared. when the backup low-power mode is entered, the supc sequentially asserts the system reset signal and disables the voltage regulator, in order to maintain only the vddbu_sw power supply. current consumption is reduced to less than one microamp for the backup part retent ion. exit from this mode is possible on multiple wake- up sources including an event on the fwup pin or wkupx pins, or a clock alarm. to exit this mode, the supc operates in the same way as system start-up by en abling the core voltage regulator and the shdn pin.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 394 20.4.2 slow clock generator the supc embeds a slow clock generator that is s upplied with the vddbu_sw power supply. as soon as vddbu_sw is supplied, both the crystal oscillator and the embedded rc oscillator ar e powered up, but only the embedded rc oscillator is enabled. th is allows the slow clock to be valid in a short time (about 100 s). the user can select the crystal oscillator to be the source of the slow clock, as it provides a more accurate frequency. the command is executed by writing the supply controller cont rol register (supc_cr) with the xtalsel bit at 1, resultin g in the following sequence: 1. the crystal oscillator is enabled. 2. a number of slow rc oscillator clo ck periods is counted to cover the start-up time of the crystal oscillator (refer to the electrical characte ristics for information on 32 khz cr ystal oscillator start-up time). 3. the slow clock is switched to t he output of the crystal oscillator. 4. the rc oscillator is disabled to save power. the switching time may vary depending on the slow rc oscillator clock frequency range. the switch of the slow clock source is glitch-free. the oscsel bit of the supply controller status register (supc_sr) indicates that the switchover has completed. reverting to the rc oscillator is only possible by shutting down the vddbu_sw power supply. if the crystal oscillator is not needed, the xin32 and xout32 pi ns should be le ft unconnected. the user can also put the cr ystal oscillator in by pass mode instead of connecting a cr ystal. in this case, the user has to provide the external clock signal on xin32. for det ails of input characteristics of the xin32 pin, see the section ?electrical characteristics?. to enter bypass mode, the oscbypass bit of the supply controller mode register (supc_mr) must be set to 1 before writing a 1 to the bit xtalsel. 20.4.3 core voltage regulator control/low-power backup mode the supc can be used to control the embedded voltage regulator. the voltage regulator automatically adapts its quiescent current depending on the required load current. for details, see the section ?electrical characteristics?. the voltage regulator can be switched off and the device put in backup mode by setting the bit vroff in supc_cr. this asserts the system reset signal after the write resynchronization time, which lasts two slow clock cycles (worst case). once the system reset signal is asserted, the processor and the peripherals are stopped one slow clock cycle before the core voltage regulator shuts off and the shdn pin is pulled down to ground. when the embedded voltage regulator is not used and vddcor e is supplied via an external supply, the voltage regulator can be disabled. this is done by clearing the onreg bit in supc_mr. 20.4.4 segmented lcd voltage regulator control the supc can be used to select the power supply sour ce of the segmented lcd (slcd) voltage regulator. this selection is done by the lcdmode field in supc_mr. after a backup reset, the lcdmode field is at 0. no power supply source is selected and the slcd reset signal is asserted. the status of the slcd controller (slcdc) reset is given by the lcds field in supc_ sr. ? if lcdmode is written to 2 while it is at 0, after the write resynchronization time (a bout 2 slow clock cycles), the external power supply source is selected, then after one slow clock cycle, the slcdc reset signal is released. ? if lcdmode is written to 0 while it is at 2, after the write resynchronization time (a bout 2 slow clock cycles), the slcdc reset signal is asserted, then after one slow clock cycle, the external power supply source is deselected.
395 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? if lcdmode is written to 3 while it is at 0, after the write resynchronization time (a bout 2 slow clock cycles), the internal power supply source is selected and the embedded regulator is turned on, then after 15 slow clock cycles, the slcdc reset signal is released. ? if lcdmode is written to 0 while it is at 3, after the write resynchronization time (a bout 2 slow clock cycles), the slcdc reset signal, then after one slow clock cycl e, the internal power supp ly source is deselected. there are several restrictions concer ning the write of the lcdmode field: ? the user must check that the previous power supply selection is done before writing lcdmode again. to do so, the user must check that the lcds flag has the correct value. if lcdmode is cleared, the lcds flag is cleared. if lcdmode is set to 2 or 3, the lcds flag is set. ? writing lcdmode to 2 while it is at 3 or writing lcdmode to 3 while it is at 2 is forbidden and has no effect. ? before writing lcdmode to 2, the user must ensure that the external power supply is ready and supplies the vddlcd pin. ? before writing lcdmode to 3, the user must ensure that the external power supply does not supply the vddlcd pin. the slcd can be used in all low-power modes. 20.4.5 using backup battery/automatic power switch the power switch automatica lly selects either vddbu or vddio as a power source. as soon as vddio is present (higher than 1.9v), it supplies the backup ar ea of the device (vddbu_sw = vddio) even if the voltage of vddbu is higher than vddio. if not, the backup area is supplied by the vddbu voltage source (vddbu_sw = vddbu). for more information on power supply schematics, refer to the section ?power supply?. 20.4.6 supply monitor the supc embeds a supply monitor located in the vd dbu_sw power domain and which monitors vddio power supply. the supply monitor can be used to prev ent the processor from falling into an unpredictable state if the main power supply drops below a certain level. the threshold of the supply monitor is programmable. it can be selected from 1.9v to 3.4v by steps of 100 mv. this threshold is configured in t he smth field of the supply contro ller supply monitor mode register (supc_smmr). the supply monitor can also be enabled during one slow clock period on every one of either 32, 256 or 2048 slow clock periods, depending on the user selection. this is configured in the smsmpl field in supc_smmr. enabling the supply monitor for such reduced times divides the typical supply monitor power consumption by factors of 2, 16 or 128, respectively, if continuous monitoring of the vddio power supply is not required. a supply monitor detection can either generate a system reset (vddcore_nreset signal is asserted) or a system wake-up. generating a system reset when a supply moni tor detection occurs is enab led by setting the smrsten bit in supc_smmr. waking up the system when a supply monitor detection occu rs is enabled by setting the smen bit in the supply controller wake-up mode register (supc_wumr). the supc provides two status bits for the supply monitor in the supc_sr. these bits determines whether the last wake-up was due to the supply monitor: ? the smos bit provides real-time information, updated at each measurement cycle or updated at each slow clock cycle, if the measurement is continuous. ? the sms bit provides saved information and shows a su pply monitor detection has occurred since the last read of supc_sr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 396 the sms bit generates an interrupt if the smien bit is set in supc_smmr. figure 20-2. supply monitor status bit and associated interrupt supply monitor on 3.3 v 0 v threshold sms and supc interrupt read supc_sr periodic sampling continuous sampling (smsmpl = 1)
397 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 20.4.7 backup power supply reset 20.4.7.1 raising the backup power supply as soon as the backup voltage vddbu_sw rises, the 32 khz rc oscillator is powered up and the zero-power power-on reset cell maintains it s output low as long as vddbu_sw has not reached its target voltage. during this time, the supc is reset. w hen the vddbu_sw voltage becomes valid and zero-power power-on reset signal is released, a counter is started for five slow clock cycles . this is the period required for the 32 khz rc oscillator to stabilize. after this time, the shdn pin is asserted high and the core voltage regulator is enabled. the core power supply rises and the brownout detector provides the core regulat or status as soon as the core voltage vddcore is valid. the system reset signal is then released to the reset cont roller after the core voltage status has been confirmed as being valid for at least one slow clock cycle. figure 20-3. raising th e vddbu_sw power supply 20.4.7.2 shdn output pin the shdn pin is designed to drive the enable pin of an exte rnal voltage regulator. this pin is controlled by the vroff bit in supc_cr. when the device goes into backup mode (bit vroff set), the shdn pin is asserted low. upon a wake-up event, the shdn pin is released (vddbu level). zero-power power-on reset cell output 22 - 42 khz rc oscillator output fast rc oscillator output backup power supply shdn core regulator status from bod core system reset (vddcore_nreset) nrst (no ext. drive assumed) processor reset (core 0 only) note: after processor reset rising, the core starts fetching instructions from flash at 4 mhz. peripheral reset 7 x slow clock cycles 3 x slow clock cycles 2 x slow clock cycles 6.5 x slow clock cycles t on voltage regulator zero-power por core power supply rstc.erstl (5 for startup slow rc + 2 for synchro.) default = 2
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 398 20.4.8 system reset the supc manages the system reset signal (vddcore_nreset) to the re set controller, as described in section 20.4.7 ?backup power supply reset? . the system reset signal is normally asserted before shutting down the core power supply and released as soon as the core power supply is correctly regulated. there are two additional sources which can be programmed to activate the system reset signal: ? a supply monitor detection ? a brownout detection 20.4.8.1 supply monitor reset the supply monitor can generate a reset of the system. this can be enabled by setting the smrsten bit in supc_smmr. if smrsten is set and if a supply moni tor detection occurs, the system reset signal is immediately activated for a minimum of one slow clock cycle. 20.4.8.2 brownout detector reset the brownout detector provides the co re voltage status signal (bodcore_ou t) to the supc which indicates that the voltage regulation is operating as pr ogrammed. if this signal is lost for longer than one slow clock period while the voltage regulator is enabled, the supc can assert a system reset signal. this feature is enabled by setting bodrsten in supc_mr. if bodrsten is set and the voltage regulation is lost (o utput voltage of the regulato r too low), the system reset signal is asserted for a minimum of one slow clock cycle and then released if the core voltage status has been reactivated. the bodrsts bit is set in supc_s r, indicating the sour ce of the last reset. the system reset signal remains active as long as the core voltage status signal (bodcore_out) indicates a powerfail condition. 20.4.8.3 power-on-reset on vddbu_sw the power-on-reset monitors vddbu_sw. it is active by default and monitors voltage at start-up but also during power-down. it can be deactivated by clearing the buppo ren bit in supc_mr. if vddbu_sw goes below the threshold voltage, the chip is reset. note that due to the automatic power switch, vddbu_sw can be either vddio or vddbu. 20.4.9 wake-up sources the wake-up events allow the device to exit backup mode. when a wake-up event is detected, the supc performs a sequence which automatically reenables the core power supply.
399 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 20-4. sam4cm16/8 wake-up sources wkup12 wkupt12 wkupen1 wkupen0 & lpdbcen0=0 debouncer slck wkupdbc wkups rtcen rtc alarm smen supply monitor core supply restart wkupis0 wkupis1 wkupis12 wkupt0 wkupt1 wkup0/tmp0 wkup1 rtten rtt alarm debouncer rtcout0 lpdbc debouncer lpdbc rtcout0 lpdbcs0 lpdbcen1 wkupt10 lpdbcen0 wkupt0 low/high level detect low/high level detect low/high level detect low/high level detect low/high level detect fwup debouncer fwupdbc fwup fwupen falling edge detector slck or or wkup10/tmp1 enable enable enable wkupen0 lpdbcs1 wkupen10 wkupen12
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 400 figure 20-5. sam4cm32 wake-up sources 20.4.9.1 force wake-up the fwup pin is enabled as a wake-up source by sett ing the fwupen bit in supc_wumr. the fwupdbc field in the same register then selects the debouncing period, which can be selected between 3, 32, 512, 4,096 or 32,768 slow clock cycles. this corresponds to about 100 s, about 1 ms, about 16 ms, about 1 28 ms and about 1 second, respectively (for a typical slow clock frequency of 32 khz). configuring fwupdbc to 0 selects an immediate wake-up, i.e., the fwup pin must be low during at least one slow clock peri od to wake up the system. if the fwup pin is asserted for a time longer than the debouncing period, a system wake-up is started and the fwups bit in supc_sr is set and remains high until the register is read. 20.4.9.2 wake-up inputs the wake-up inputs wkupx can be programmed to perf orm a system wake-up. each input can be enabled by setting the corresponding bit, wkupenx, in the wake-up inputs register (supc_wuir). the wake-up level can be selected with the corresponding polarity bit, wkuptx, also located in supc_wuir. a logical or combination of all the resulting signals triggers a debouncing counterthe wkupdbc field can be configured to select a debouncing per iod of 3, 32, 512, 4,096 or 32,768 slow clock cycles. this corresponds, respectively, to about 100 s, about 1 ms, about 16 ms, about 128 ms and about 1 second (for a typical slow clock wkup12 wkupt12 wkupen1 wkupen0 & lpdbcen0=0 debouncer slck wkupdbc wkups rtcen rtc alarm smen supply monitor core supply restart wkupis0 wkupis1 wkupis12 wkupt0 wkupt1 wkup0/tmp0 wkup1 rtten rtt alarm debouncer rtcout0 lpdbc debouncer lpdbc rtcout0 lpdbcs0 lpdbcen1 wkupt10 lpdbcen0 wkupt0 low/high level detect low/high level detect low/high level detect low/high level detect low/high level detect fwup debouncer fwupdbc fwup fwupen falling edge detector slck or or wkup10/tmp1 enable enable enable wkupen0 lpdbcs1 wkupen10 wkupen12
401 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 frequency of 32 khz). configuring wkup dbc to 0 selects an immediate wake -up, i.e., an enabled wkup pin must be active according to its polarity during a minimum of one slow clock period to wake up the core power supply. if an enabled wkupx pin holds the active polarity for a time longer than the debouncing period, a system wake-up is started and the flags wkupisx, as shown in figure 20-4 and figure 20-5 , are reported in supc_sr. this allows the user to identify the source of the wake-up. however, if a new wake-up condition occurs, the primary information is lost. no new wake-up can be detected since the primary wake-up condition has disappeared. 20.4.9.3 low-power debouncer i nputs (tamper detection pins) low-power debouncer inputs are dedicated to tamper detection. if the tamper sensor is biased through a resistor and constantly driven by the power supp ly, this leads to power consumption as long as the tamper detection switch is in its active state. to prevent power consumption when th e switch is in active state, the tamper sensor circuitry can be intermittently powered, thus, a specific waveform must be generated. the waveform can be generated using pin rtcout0 in all modes, including backup mode. refer to the section ?real-time counter (rtc)? section for waveform generation. for sam4cm devices, separate debouncers are embe dded, one for each wake-up/tamper input. see figure 20-4 and figure 20-5 . the wkup0/tmp0 and/or wkup10/tmp1 inputs can be programmed to perform a system wake-up with a debouncing done by rtcout0. this can be ena bled by setting lpdbcen0/1 in supc_wumr. these inputs can be also used when vddcore is powere d to obtain the tamper detection function with a low power debounce function and to raise an interrupt. the low-power debounce mode of operation requires the rtc output (rtcout0) to be configured to generate a duty cycle programmable pulse (i.e., out0 = 0x7 in rt c_mr) in order to create the sampling points of both debouncers. the sampling poi nt is the falling edge of the rtcout0 waveform. figure 20-6 shows an example of an application where two tamper switches are used. rtcout0 powers the external pull-up used by the tampers. figure 20-6. low-power debouncer (push-to-make switch, pull-up resistors) mcu wkup0/tmp0 wkupx/tmpx rtcout0 pull-up resistor pull-up resistor gnd gnd gnd
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 402 figure 20-7. low-power debouncer (push-to-break switch, pull-down resistors) the duration of the debouncing period is configurable. the period is identical for all debouncers (i.e., the duration cannot be adjusted separately for each debouncer). the num ber of successive identical samples to wake up the system can be configured from 2 up to 8 in the lpdbc field of supc_wumr. the period of time between two samples can be configured in the tperiod field in the rt c_mr. power parameters can be adjusted by modifying the period of time in the thigh field in rtc_mr. the wake-up polarity of the inputs can be independent ly configured by writing wkupt0 /wkupt10 bits in supc_wuir. in order to determine which wake-up/tamper pin triggers the system wake-up, a status flag lpdbcsx is associated to each low-power debouncer. these flags can be read in the supc_sr. a debounce event (tamper detection) can perform an immediate clear (0 delay) on the first half of the general- purpose backup registers (gpbr). the lpdbcclr bit must be set in supc_wumr. the clear capability for tmp1 can be individually disabled by setting the corresponding bit distmpclr1. note that it is not mandatory to use the rtcout0 pi n when using the wkup0/wkup10 pins as tampering inputs (tmp0/tmp1) in any mode. using the rtcout0 pin prov ides a ?sampling mode? to further reduce the power consumption of the tamper detection ci rcuitry. if rtcout0 is not used, t he rtc must be configured to create an internal sampling point for the debouncer logic. the peri od of time between two samples can be configured by programming the tperiod field in the rtc_mr. figure 20-8 illustrates the use of wkupx/ tmpx without the rtcout0 pin. mcu wkup0/tmp0 wkupx/tmpx rtcout0 pull-down resistors gnd gnd gnd
403 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 20-8. using wkup/tmp pins without rtcout pins 20.4.9.4 clock alarms the rtc and the rtt alarms generate a system wake-u p. this can be enabled by setting bits rtcen and rtten in supc_wumr. the supc does not provide any status, as the information is available in the us er interface of either the real-time timer or the real-time clock. 20.4.9.5 supply monitor detection the supply monitor can genera te a system wake-up. see section 20.4.6 ?supply monitor? . mcu wkup0/tmp0 wkupx/tmpx rtcout0 vdd pull-up resistor pull-up resistor gnd gnd gnd
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 404 20.5 register write protection to prevent any single software error from corrupting supc behavior, certain registers in the address space can be write-protected by settin g the wpen bit in the system controller write protection mode register (sysc_wpmr). the following registers can be write-protected: ? rstc mode register ? rtt mode register ? rtt alarm register ? rtc control register ? rtc mode register ? rtc time alarm register ? rtc calendar alarm register ? general purpose backup registers ? supply controller control register ? supply controller supply monitor mode register ? supply controller mode register ? supply controller wake-up mode register ? supply controller wake-up inputs register
405 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 20.6 supply controller (s upc) user interface the user interface of the supc is part of the system controller user interface. 20.6.1 system controller (sysc) user interface 20.6.2 supply controller (supc) user interface table 20-1. system contro ller peripheral offsets offset system controller peripheral name 0x00-0x0c reset controller rstc 0x10-0x2c supply controller supc 0x30-0x3c real time timer rtt 0x50-0x5c watchdog timer wdt 0x60-0x8c real time clock rtc 0x90-0xdc general purpose backup register gpbr 0xe0 reserved ? 0xe4 write protection m ode register sysc_wpmr 0xe8-0xf8 reserved ? 0xfc reserved ? 0x100-0x10c reinforced safety watchdog timer rswdt 0x110-0x124 timestamping registers rtc table 20-2. register mapping offset register name access reset 0x00 supply controller control register supc_cr write-only n/a 0x04 supply controller supply monitor m ode register supc_smmr read/write 0x0000_0000 0x08 supply controller mode regi ster supc_mr read/write 0x0000_a00 0x0c supply controller wake-up mode re gister supc_wumr read/write 0x0000_0000 0x10 supply controller wake-up inputs register supc_wuir read/write 0x0000_0000 0x14 supply controller status register supc_sr read-only 0x0000_0000 0x18 reserved ? ? ? 0xfc reserved ? ? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 406 20.6.3 supply controller control register name: supc_cr address: 0x400e1410 access: write-only ? vroff: voltage regulator off 0 (no_effect): no effect. 1 (stop_vreg): if key is correct, asserts the system reset signal and stops the vo ltage re gulator. ? xtalsel: crystal oscillator select 0 (no_effect): no effect. 1 (crystal_sel): if key is corr ect, switches the slow clock on the crystal oscillator output. ? key: password 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????x t a l s e lv r o f f?? value name description 0xa5 passwd writing any other value in this field aborts the write operation.
407 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 20.6.4 supply controller supply monitor mode register name: supc_smmr address: 0x400e1414 access: read/write ? smth: supply monitor threshold selects the threshold voltage of the supply monitor. refer to the section ?ele ctrical characteristics? for voltage values. ? smsmpl: supply monitor sampling period ? smrsten: supply monitor reset enable 0 (not_enable): the system reset signal is not a ffected when a supply monitor detection occurs. 1 (enable): the system reset signal is asserted when a supply monitor detection occurs. ? smien: supply monitor interrupt enable 0 (not_enable): the supc interrupt signal is not affected when a supply monitor detection occurs. 1 (enable): the supc interrupt signal is asse rted when a supply monitor detection occurs. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? smien smrsten ? smsmpl 76543210 ???? s m t h value name description 0 smd supply monitor disabled 1 csm continuous supply monitor 2 32slck supply monitor enabled one slck period every 32 slck periods 3 256slck supply monitor enabled one slck period every 256 slck periods 4 2048slck supply monitor enabled one slck period every 2,048 slck periods
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 408 20.6.5 supply controller mode register name: supc_mr address: 0x400e1418 access: read/write ? lcdvrout: lcd voltage regulator output adjusts the output voltage of the lcd voltage regulator. refer to the section ?electrical charac teristics? for voltage values. ? lcdmode: lcd controller mode of operation ? bodrsten: brownout detector reset enable 0 (not_enable): the system reset signal is no t affected when a brownout detection occurs. 1 (enable): the system reset signal is asserted when a brownout detection occurs. ? boddis: brownout detector disable 0 (enable): the core brownout detector is enabled. 1 (disable): the core brow nout detector is disabled. ? onreg: voltage regulator enable 0 (onreg_unused): internal voltage regulator is not used (external power supply is used). 1 (onreg_used): internal voltage regulator is used. ? bupporen: backup area power-on reset enable 0 (buppor_disable): disables the backup por. 1 (buppor_enable): enab les the backup por. note: the value written in bupporen is effective when buppors has the same value in supply controller status register . ? oscbypass: oscillator bypass 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???o s c b y p a s s???? 15 14 13 12 11 10 9 8 b u p p o r e no n r e gb o d d i sb o d r s t e n???? 76543210 ? ? lcdmode lcdvrout value name description 0 lcdoff the internal supply source and the extern al supply source are both deselected (off mode). 2 lcdon_extvr the external supply source for lcd (vddlcd) is selected (the lcd voltage regulator is in hi-z mode). 3 lcdon_invr the internal supply source for lcd (the lcd voltage regulator) is selected (active mode).
409 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 0 (no_effect): no effect. clock selection depends on xtalsel value. 1 (bypass): the 32 khz crystal oscillator is bypass ed if xtalsel = 1. oscbypass mu st be set before setting xtalsel. ? key: password key value name description 0xa5 passwd writing any other value in this field aborts the write operation.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 410 20.6.6 supply controller wake-up mode register name: supc_wumr address: 0x400e141c access: read/write ? fwupen: force wake-up enable 0 (not_enable): the force wake-up pin has no wake-up effect. 1 (enable): the force wake-up pin low forces a system wake-up. ? smen: supply monitor wake-up enable 0 (not_enable): the supply monitor detection has no wake-up effect. 1 (enable): the supply monitor detection forces a system wake-up. ? rtten: real-time timer wake-up enable 0 (not_enable): the rtt alarm signal has no wake-up effect. 1 (enable): the rtt alarm signal forces a system wake-up. ? rtcen: real-time clock wake-up enable 0 (not_enable): the rtc alarm signal has no wake-up effect. 1 (enable): the rtc alarm signal forces a system wake-up. ? lpdbcen0: low-power debouncer enable wkup0/tmp0 0 (not_enable): the wkup0/tmp0 input pin is not connected to the low-power debouncer. 1 (enable): the wkup0/tmp0 input pin is connected to the low-power debouncer and can force a system wake-up. ? lpdbcen1: low-power debouncer enable wkup10/tmp1 0 (not_enable): the wkup10/tmp1 input pin is not connected to the low-power debouncer. 1 (enable): the wkup10/tmp1 input pin is connected to the low-power debouncer and can force a system wake-up. ? lpdbcclr: low-power debouncer clear 0 (not_enable): a low-power debounce event does not create an immediate clear on the first half of gpbr registers. 1 (enable): a low-power debounce event on wkup0/tmp0 or wkup10tmp1(if distmpclr1 is cleared) generates an immediate clear on the first half of gpbr registers. 31 30 29 28 27 26 25 24 ???d i s t s t m p 1??? distmpclr 1 23 22 21 20 19 18 17 16 ????? l p d b c 15 14 13 12 11 10 9 8 ? wkupdbc ? fwupdbc 76543210 lpdbcclr lpdbcen1 lpdbcen0 ? rtcen rtten smen fwupen
411 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? fwupdbc: force wake-up debouncer period ? wkupdbc: wake-up inputs debouncer period ? lpdbc: low power debouncer period ? distmpclr1: disable gpbr clear command from wkup10/tmp1 pin 0 (enable): the wkup10/tmp1 input pin can clear the g pbr (if lpdbcclr is enabled) when tamper is detected. 1 (disable): the wkup10/tmp1 input pin has no effect on the gpbr value (no clear on tamper detection). ? diststmp1: disable timestamp from wkup10/tmp1 pin 0 (enable): a tamper de tection on wkup10/tmp1 pin generates a timestamp. 1 (disable): a tamper detection on wkup10/tmp1 does not generate a report in timestamp register. value name description 0 immediate immediate, no deboun cing, detected active at least on one slow clock edge. 1 3_sclk fwup shall be low for at least 3 slck periods 2 32_sclk fwup shall be low for at least 32 slck periods 3 512_sclk fwup shall be low for at least 512 slck periods 4 4096_sclk fwup shall be low for at least 4,096 slck periods 5 32768_sclk fwup shall be low for at least 32,768 slck periods value name description 0 immediate immediate, no deboun cing, detected active at least on one slow clock edge. 1 3_sclk wkupx shall be in its active state for at least 3 slck periods 2 32_sclk wkupx shall be in its active state for at least 32 slck periods 3 512_sclk wkupx shall be in its active state for at least 512 slck periods 4 4096_sclk wkupx shall be in its active state for at least 4,096 slck periods 5 32768_sclk wkupx shall be in its active state for at least 32,768 slck periods value name description 0 disable disable the low-power debouncers. 1 2_rtcout0 wkup0/10tmp0/1 in active state for at least 2 rtcout0 periods 2 3_rtcout0 wkup0/10tmp0/1 in active state for at least 3 rtcout0 periods 3 4_rtcout0 wkup0/10tmp0/1 in active state for at least 4 rtcout0 periods 4 5_rtcout0 wkup0/10tmp0/1 in active state for at least 5 rtcout0 periods 5 6_rtcout0 wkup0/10tmp0/1 in active state for at least 6 rtcout0 periods 6 7_rtcout0 wkup0/10tmp0/1 in active state for at least 7 rtcout0 periods 7 8_rtcout0 wkup0/10tmp0/1 in active state for at least 8 rtcout0 periods
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 412 20.6.7 supply controller wake-up inputs register name: supc_wuir address: 0x400e1420 access: read/write ? wkupenx: wkupx input enable 0 (disable): the corresponding wake-up input has no wake-up effect. 1 (enable): the corresponding wake-up input forces a system wake-up. ? wkuptx: wkupx input type 0 (low): a low level for a period defin ed by wkupdbc in supc_wumr on the corresponding wake-up input forces a system wake-up. 1 (high): a high level for a period defined by wkupdbc in supc_wumr on the corresponding wake-up input forces a system wake-up. 31 30 29 28 27 26 25 24 ? ? ? wkupt12 wkupt11 wkupt10 wkupt9 wkupt8 23 22 21 20 19 18 17 16 wkupt7 wkupt6 wkupt5 wkupt4 wkupt3 wkupt2 wkupt1 wkupt0 15 14 13 12 11 10 9 8 wkupen15 wkupen14 wkupen13 wkupen12 wkupen11 wkupen10 wkupen9 wkupen8 76543210 wkupen7 wkupen6 wkupen5 wkupen4 wkupen3 wkupen2 wkupen1 wkupen0
413 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 20.6.8 supply controller status register name: supc_sr address: 0x400e1424 access: read-only note: because of the asynchronism between the slow clock (sclk) and the system clock (mck), the st atus register flag reset is ta ken into account only two slow clock cycles after the read of the supc_sr. ? fwups: fwup wake-up status (cleared on read) 0 (no): no wake-up due to the assertion of the fwup pin has occurred since the last read of supc_sr. 1 (present): at least one wake-u p due to the assertion of t he fwup pin has occurred sinc e the last read of supc_sr. ? wkups: wkup wake-up stat us (cleared on read) 0 (no): no wake-up due to the assertion of the wkup pins has occurred since the last read of supc_sr. 1 (present): at least one wake-up due to the asse rtion of the wkup pins has occurr ed since the last read of supc_sr. ? smws: supply monitor detection wake-up status (cleared on read) 0 (no): no wake-up due to a supply monitor detec tion has occurred since the last read of supc_sr. 1 (present): at least one wake -up due to a supply monitor detection has occurr ed since the last read of supc_sr. ? bodrsts: brownout detector reset status (cleared on read) 0 (no): no core brownout rising edge event has been detected since the last read of supc_sr. 1 (present): at least one brownout outp ut rising edge event ha s been detected since the last read of supc_sr. when the voltage remains below the defined threshold, there is no rising edge event at the output of the brownout detec- tion cell. the rising edge event occurs only when there is a voltage transition below the threshold. ? smrsts: supply monitor reset status (cleared on read) 0 (no): no supply monitor detection has generated a system reset since the last read of supc_sr. 1 (present): at least one supply monito r detection has gener ated a system reset since the last read of supc_sr. ? sms: supply monitor status (cleared on read) 0 (no): no supply monitor detection since the last read of supc_sr. 1 (present): at least one supply monitor de tection since the last read of supc_sr. ? smos: supply monitor output status 31 30 29 28 27 26 25 24 ? ? ? wkupis12 wkupis11 wkupis10 wkupis9 wkupis8 23 22 21 20 19 18 17 16 wkupis7 wkupis6 wkupis5 wkupis4 wkupis3 wkupis2 wkupis1 wkupis0 15 14 13 12 11 10 9 8 buppors lpdbcs1 lpdbcs0 fwupis ? ? ? lcds 76543210 oscsel smos sms smrsts bodrsts smws wkups fwups
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 414 0 (high): the supply monitor detected vddio hig her than its threshold at its last measurement. 1 (low): the supply monitor detected vddio lowe r than its threshold at its last measurement. ? oscsel: 32 khz oscillator selection status 0 (rc): the slow clock, slck, is gener ated by the em bedded 32 khz rc oscillator. 1 (cryst): the slow clock, slck, is gen erated by the 32 khz crystal oscillator. ? lcds: lcd status 0 (disabled): lcd controller is disabled. 1 (enabled): lcd controller is enabled. ? fwupis: fwup input status 0 (low): fwup input is tied low. 1 (high): fwup input is tied high. ? lpdbcs0: low power debouncer wake-up status on wkup0/tmp0 (cleared on read) 0 (no): no tamper detection or wake-up due to the assertion of the wkup0/tmp0 pin has occurred since the last read of supc_sr. 1 (present): at least one tamper dete ction and wake-up (if enab led by wkupen0) due to the assertion of the wkup0/tmp0 pin has occurred since the last read of su pc_sr. the supc interrupt lin e is asserted while lpdbcs0 is 1. ? lpdbcs1: low power debouncer wake-up status on wkup10/tmp1 (cleared on read) 0 (no): no tamper detection or wake-up due to the assertion of the wkup1 0 pin has occurred since the last read of supc_sr. 1 (present): at least one tamper dete ction and wake-up (if enab led by wkupen10) due to the assertion of the wkup10/tmp1 pin has occurred since the last read of supc _sr. the supc interrupt line is asserted while lpdbcs1 is 1. ? buppors: backup area power-on reset status 0 (buppor_disabled): ba ckup por is disabled. 1 (buppor_enabled): backup por is enabled. note: the value written in bupporen is effective when bupporens has the same value in supply controller status register . ? wkupisx: wkupx input status (cleared on read) 0 (dis): the corresponding wake-up input is disabled, or wa s inactive at the time the debouncer triggered a wake-up event. 1 (en): the corresponding wake-up input was active at the ti me the debouncer triggered a wake-up event since the last read of supc_sr.
415 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 20.6.9 system controller write protection mode register name: sysc_wpmr access: read/write for more information on write pr otection registers, refer to section 20.5 ?register write protection? . ?wpen: 0: disables the write protection if wpkey corresponds to 0x525443 (sysc in ascii). 1: enables the write protection if wpkey corresponds to 0x525443 (sysc in ascii). see section 20.5 ?register write protection? for the list of registers that can be protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x525443 passwd writing any other value in this field ab orts the write operati on of the wpen bit. always reads as 0.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 416 21. general purpose backup registers (gpbr) 21.1 description the system controller embeds 16 general purpose backup registers. it is possible to generate an immediat e clear of the content of general purpose backup registers 0 to 7 (first half), if a tamper event is detected on one of the tamper pins , tmp0 to tmp3. the content of the other general purpose backup registers (second half) remains unchanged. the tamper events on pins tmp1 to tmp3 to perform a gpbr clear are configurable in the supply controller. the tmp0 tamper event always performs an immediate clear. the supply controller module must be programmed accord ingly. in the register supc_wumr in the supply controller module, lpdbcclr, lpdbcen0, lpdbce n1, lpdbcen2 and and lpdbcen3 bit must be configured to 1 and lpdbc must be other than 0. if a tamper event has been detected, it is not possible to write to the general purpose backup registers while the lpdbcsx flags are not cleared in the supply controller status register (supc_sr). 21.2 embedded characteristics ? 16 32-bit general purpose backup registers
417 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 21.3 general purpose backup regi sters (gpbr) user interface table 21-1. register mapping offset register name access reset 0x0 general purpose backup regist er 0 sys_gpbr0 read/write 0x00000000 ... ... ... ... ... 0xcc general purpose backup regist er 15 sys_gpbr15 read/write 0x00000000
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 418 21.3.1 general purpose backup register x name: sys_gpbrx address: 0x400e1490 access: read/write these registers are reset at first power-up and on each loss of vddbu. ? gpbr_value: value of gpbr x if a tamper event has been detected, it is not possible to write gpbr_value as long as the lpdbcs0 or lpdbcs3 flags have not been cleared in the supply controller status register (supc_sr). 31 30 29 28 27 26 25 24 gpbr_value 23 22 21 20 19 18 17 16 gpbr_value 15 14 13 12 11 10 9 8 gpbr_value 76543210 gpbr_value
419 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 22. enhanced embedded flash controller (eefc) 22.1 description the enhanced embedded flash controller (eefc) ensures the interface of the flash block with the 32-bit internal bus. its 128-bit or 64-bit wide memory interface increases performance. it also manages the programming, erasing, locking and unlocking sequences of the flash using a fu ll set of commands. one of the commands returns the embedded flash descriptor definition th at informs the system about the flas h organization, thus making the software generic. 22.2 embedded characteristics ? interface of the flash block with the 32-bit internal bus ? increases performance in thumb-2 mode with 128-bit or 64-bit-wide memory interface up to 100 mhz ? code loop optimization ? 128 lock bits, each protecting a lock region ? 3 general-purpose gpnvm bits ? one-by-one lock bit programming ? commands protected by a keyword ? erase the entire flash ? erase by plane ? erase by sector ? erase by pages ? possibility of erasin g before programming ? locking and unlocking operations ? ecc single and multiple error flags report ? possibility to read the calibration bits 22.3 product dependencies 22.3.1 power management the enhanced embedded flash controller (eefc) is c ontinuously clocked. the power management controller has no effect on its behavior. 22.3.2 interrupt sources the eefc interrupt line is connected to the interrupt controller. using the eefc interrupt requires the interrupt controller to be programmed first. the eefc interrupt is ge nerated only if the value of bit eefc_fmr.frdy is 1. table 22-1. peripheral ids instance id efc 6
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 420 22.4 functional description 22.4.1 embedded flash organization the embedded flash interfaces directly with the 32-bit internal bus. the embedded flash is composed of: ? two memory planes organized in several pages of the same size for dual-plane devices ? two 128-bit or 64-bit read buffers used for code read optimization ? one 128-bit or 64-bit read buffer used for data read optimization ? one write buffer that manages page progr amming. the write buffer size is equal to the page size. this buffer is write-only and accessible all along the 1 mbyte address space, so that each word can be written to its final address. ? several lock bits used to protect write/erase operation on several pages (lock region). a lock bit is associated with a lock region composed of several pages in the memory plane. ? several bits that may be set and cleared through the eefc interface, called general-purpose non-volatile memory bits (gpnvm bits) the embedded flash size, the page size, the organization of lock regions and the defin ition of gpnvm bits are specific to the device. the eefc returns a descriptor of the flash controller after a get flash descriptor command has been issued by the application (see ?get flash descriptor command? on page 426 ).
421 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 22-1. embedded flash organization for dual-plane devices start address page 0 memory plane 0 page (m-1) page (n*m-1) start address + memory plane size -1 start address + memory plane size lock bit 0 lock bit 1 lock bit (n-1) lock bit n lock bit (n+1) start address + 2*memory plane size -1 lock bit (2*n - 1) lock region n lock region (n+1) memory plane 1 page (n*m) page (n*(m+1) - 1) page (2*n*m-1) lock region 0 lock region 1 lock region (n-1) lock region (2*n-1)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 422 22.4.2 read operations an optimized controller manages embedded flash reads, thus increasing performance when the processor is running in thumb-2 mode by means of the 128- or 64-bit-wide memory interface. the flash memory is accessible through 8-, 16- and 32-bit reads. as the flash block size is smaller than the address s pace reserved for the internal memory area, the embedded flash wraps around the address space and appears to be repeated within it. the read operations can be performed with or without wait states. wait states must be programmed in the field fws (flash read wait state) in the flash mode register (eefc_fmr). defining fws as 0 enables the single- cycle access of the embedded flash. refer to the ?ele ctrical characteristics? section for more details. 22.4.2.1 128-bit or 64-bit access mode by default, the read accesses of the flash are performed through a 128-bit wide memory interface. it improves system performance especially when tw o or three wait states are needed. for systems requiring only 1 wait stat e, or to focus on current consumption rather than performance, the user can select a 64-bit wide memory a ccess via the bit eefc_fmr.fam. refer to the ?electrical characteri stics? section for more details. 22.4.2.2 code read optimization code read optimization is enabled if the bit eefc_fmr.scod is cleared. a system of 2 x 128-bit or 2 x 64-bit buffers is added in order to optimize sequential code fetch. note: immediate consecutive code read accesses are not mandatory to benefit from this optimization. the sequential code read optimization is enabled by default. if the bit eefc_f mr.scod is set to 1, these buffers are disabled and the sequential code read is no longer optimized. another system of 2 x 128-bit or 2 x 64- bit buffers is added in order to opti mize loop code fetch. refer to ?code loop optimization? on page 423 for more details. figure 22-2. code read optimization for fws = 0 note: when fws is equal to 0, all the accesses are performed in a single-cycle access. flash access buffer 0 (128bits) master clock arm request (32-bit) xxx data to arm bytes 0?15 bytes 16?31 bytes 32?47 bytes 0?15 buffer 1 (128bits) bytes 32?47 bytes 0?3 bytes 4?7 bytes 8?11 bytes 12?15 bytes 16?19 bytes 20?23 bytes 24?27 xxx xxx bytes 16?31 @byte 0 @byte 4 @byte 8 @byte 12 @byte 16 @byte 20 @byte 24 @byte 28 @byte 32 bytes 28?31
423 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 22-3. code read optimization for fws = 3 note: when fws is included between 1 and 3, in case of sequential reads, the first access takes (fws+1) cycles, the other ones o nly 1 cycle. 22.4.2.3 code loop optimization code loop optimization is enabled when the bit eefc_fmr.cloe is set to 1. when a backward jump is inserted in the code, the pipeline of the sequential optimization is broken and becomes inefficient. in this case, the loop code read optimization takes over from the sequential code read optimization to prevent the insertion of wait states. the loop code read op timization is enabled by default. in eefc_fmr, if the bit cloe is reset to 0 or the bit scod is set to 1, these bu ffers are disabled and the loop code read is not optimized. when code loop optimization is enabled, if inner loop body instructions l 0 to l n are positioned from the 128-bit flash memory cell m b0 to the memory cell m p1 , after recognition of a first backw ard branch, the first two flash memory cells m b0 and m b1 targeted by this branch are cached for fast access from the processor at the next loop iteration. then by combining the sequential prefetch (described in section 22.4.2.2 ?code read optimization? ) through the loop body with the fast read access to the loop entry cac he, the entire loop can be iterated with no wait state. figure 22-4 illustrates code lo op optimization. figure 22-4. code loop optimization flash access buffer 0 (128bits) master clock arm request (32-bit) data to arm buffer 1 (128bits) 0?3 xxx xxx bytes 16?31 @byte 0 @4 @8 bytes 0?15 bytes 16?31 bytes 32?47 bytes 48?63 xxx bytes 0?15 4?7 8?11 12?15 @12 @16 @20 24?27 28?31 32?35 36?39 16?19 20?23 40?43 44?47 @24 @28 @32 @36 @40 @44 @48 @52 bytes 32?47 48?51 l n l n-1 l n-2 l n-3 l n-4 l n-5 l 5 l 4 l 3 l 2 l 1 l 0 b 1 b 2 b 3 b 4 b 5 b 6 b 7 b 0 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p 0 m b0 m b0 m b1 m p0 m p1 backward address jump 2x128-bit loop entry cache 2x128-bit prefetch buffer l 0 loop entry instruction l n loop end instruction flash memory 128-bit words m b0 branch cache 0 m b1 branch cache 1 m p0 prefetch buffer 0 m p1 prefetch buffer 1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 424 22.4.2.4 data read optimization the organization of the flash in 128 bits (or 64 bits) is associated with two 128-bit (or 64-bit) prefetch buffers and one 128-bit (or 64-bit) data read buffer, thus providing ma ximum system performance. this buffer is added in order to store the requested data plus al l the data contained in the 128-bit ( 64-bit) aligned data. this speeds up sequential data reads if, for example, fws is equal to 1 (see figure 22-5 ). the data read optimization is enabled by default. if the bit eefc_fmr.scod is set to 1, this buff er is disabled and the data read is no longer optimized. note: no consecutive data read accesses are ma ndatory to benefit from this optimization. figure 22-5. data read optimization for fws = 1 22.4.3 flash commands the eefc offers a set of commands to manage programming the flash memory, locking and unlocking lock regions, consecutive programming, lo cking and full flash erasing, etc. for dual-plane devices, command and read operations can be performed in parallel only on different memory planes. code can be fetched from one memory plane while a write or an erase operation is performed on another . the commands are listed in the following table. flash access buffer (128bits) master clock arm request (32-bit) xxx data to arm bytes 0?15 bytes 16?31 bytes 0?15 bytes 0?3 4?7 8?11 12?15 16?19 20?23 xxx bytes 16?31 @byte 0 @ 4 @ 8 @ 12 @ 16 @ 20 @ 24 @ 28 @ 32 @ 36 xxx bytes 32?47 24?27 28?31 32?35 table 22-2. set of commands command value mnemonic get flash descriptor 0x00 getd write page 0x01 wp write page and lock 0x02 wpl erase page and write page 0x03 ewp erase page and write page then lock 0x04 ewpl erase all 0x05 ea erase plane 0x06 epl erase pages 0x07 epa set lock bit 0x08 slb clear lock bit 0x09 clb get lock bit 0x0a glb set gpnvm bit 0x0b sgpb clear gpnvm bit 0x0c cgpb
425 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 in order to perform one of these commands, select the desired command using the fcmd field in the flash command register (eefc_fcr). as soon as eefc_fcr is written, the frdy flag and the fvalue field in the flash result register (eefc_frr) are automatically cleared. once the current command has completed, the frdy flag is automatically set. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the corresponding interrupt line of the interrupt controller is activated. (note that this is true for all commands except for the stui command. the frdy flag is no t set when the stui co mmand has completed.) all the commands are protected by the same keyword, which must be written in the eight highest bits of eefc_fcr. writing eefc_fcr with data that does not contain the correct key and/or with an invalid command has no effect on the whole memory plane, but the fcmde flag is set in the flash status register (eefc_fsr). this flag is automatically cleared by a read access to eefc_fsr. when the current command writes or erases a page in a locked region, the command has no effect on the whole memory plane, but the flocke flag is set in eefc_fsr. this flag is automatically cleared by a read access to eefc_fsr. get gpnvm bit 0x0d ggpb start read unique identifier 0x0e stui stop read unique identifier 0x0f spui get calib bit 0x10 gcalb erase sector 0x11 es write user signature 0x12 wus erase user signature 0x13 eus start read user signature 0x14 stus stop read user signature 0x15 spus table 22-2. set of commands (continued) command value mnemonic
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 426 figure 22-6. command state chart 22.4.3.1 get flash descriptor command this command provides the system with information on the flash organization. the system can take full advantage of this information. for instance, a device co uld be replaced by one with more flash capacity, and so the software is able to adapt itself to the new configuration. to get the embedded flash descriptor, the application writ es the getd command in eef c_fcr. the first word of the descriptor can be read by the software application in eefc_frr as soon as the frdy flag in eefc_fsr rises. the next reads of eefc_frr provide the followin g word of the descriptor. if extra read operations to eefc_frr are done after the last word of the descriptor has been returned, the eefc_frr value is 0 until the next valid command. for dual-plane devices with two embedded flash controllers, the get flash descriptor command must be performed on each controller. check if frdy flag set no yes read status: mc_fsr write fcmd and pagenb in flash command register check if flocke flag set check if frdy flag set no read status: mc_fsr yes yes locking region violation no check if fcmde flag set yes no bad keyword violation command successfull
427 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 22.4.3.2 write commands several commands are used to program the flash. only 0 values can be programmed using flash technology; 1 is the erased value. in order to program words in a page, the page must first be erased. commands are availabl e to erase the full memory plane or a given number of pages. with the ewp and ewpl commands, a page erase is done automatically before a page programming. after programming, the page (the entire lock region) c an be locked to prevent miscellaneous write or erase sequences. the lock bit can be automatically set after page programming using wpl or ewpl commands. data to be programmed in the flash must be written in an internal latch buffer before writing the programming command in eefc_fcr. data can be written at their final de stination address, as the latch buffer is mapped into the flash memory address space and wraps around within this flash address space. byte and half-word ahb accesses to the latch buffer are not allowed. only 32-bit word accesses are supported. 32-bit words must be written continuously, in either as cending or descending order. writ ing the latch buffer in a random order is not permitted. this prevents mapping a c-code structure to the latch buffer and accessing the data of the structure in any order. it is instead reco mmended to fill in a c-code structur e in sram and copy it in the latch buffer in a continuous order. write operations in the latch buffer are performed with the number of wait states programmed for reading the flash. the latch buffer is automatically re-initialized, i.e., wri tten with logical 1, after execution of each programming command. the programming sequence is as follows: 1. write the data to be programmed in the latch buffer. 2. write the programming command in eefc_fcr. th is automatically clears the bit eefc_fsr.frdy. 3. when flash programming is completed, the bit eefc_ fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrupt line of the eefc is activated. three errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? lock error: the page to be programmed belongs to a locked region. a command must be run previously to unlock the corresponding region. ? flash error: when programming is completed, the writeverify test of the flash memory has failed. table 22-3. flash descriptor definition symbol word index description fl_id 0 flash interface description fl_size 1 flash size in bytes fl_page_size 2 page size in bytes fl_nb_plane 3 number of planes. for dual-plane devices, a plane can be erased or written while read operations are performed on another plane . fl_plane[0] 4 number of bytes in the first plane fl_plane[fl_nb_plane-1] 4 + fl_nb_plane - 1 number of bytes in the last plane fl_nb_lock 4 + fl_nb_plane number of lock bits. a bit is associat ed with a lock region. a lock bit is used to prevent write or erase operations in the lock region. fl_lock[0] 4 + fl_nb_plane + 1 number of bytes in the first lock region
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 428 only one page can be programmed at a time. it is po ssible to program all the bits of a page (full page programming) or only some of the bits of the page (partial page programming). depending on the number of bits to be programmed within the page, the eefc adapts the write operations required to program the flash. when the programming page command is given, the eefc starts the programming sequence and all the bits written at 0 in the latch buffer are cleared in the flash memory array. during programming, i.e., unt il eefc_fsr.fdry rises, access to the flash is not allowed. full page programming to program a full page, all the bits of the page must be erased before writing the latch buffer and launching the wp command. the latch buffer must be written in ascending order, starting from the first address of the page. see figure 22-7, "full page programming" . partial page programming to program only part of a page using the wp co mmand, the following constraints must be respected: ? data to be programmed must be contained in integer multiples of 64-bit address-aligned words. ? 64-bit words can be programmed only if all the corresponding bits in the flash array are erased (at logical value 1). see figure 22-8, "partial page programming" programming bytes individual bytes can be programmed us ing the partial page programming mode. in this case, an area of 64 bits must be reserved for each byte, as shown in figure 22-9, "programming bytes in the flash" .
429 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 22-7. full page programming ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c before programming: unerased page in flash array ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe step 1: flash array after page erase ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff address space for page n address space for latch buffer step 2: writing a page in the latch buffer de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca ca fe ca fe 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c address space for page n step 3: page in flash array after issuing wp command and frdy=1 de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca ff ff ff ff 32 bits wide 32 bits wide
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 430 figure 22-8. partial page programming 32 bits wide 32 bits wide ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c step 2: flash array after programming 64-bit at address 0xx08 (write latch buffer + wp) ca fe ca fe ca fe ca fe ff ff ff ff ff ff ff ff address space for page n ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff step 1: flash array after page erase c a fe c a f e c a fe c a f e 32 bits wide ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c step 3: flash array after programming a second 64-bit data at address 0xx00 (write latch buffer + wp) ca fe ca fe ca fe ca fe ff ff ff ff ff ff ff ff ff ff ff ff ca fe ca fe ca fe ca fe 32 bits wide 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c step 4: flash array after programming a 128-bit data word at address 0xx10 (write latch buffer + wp) ca fe ca fe ca fe ca fe ff ff ff ff ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe
431 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 22-9. programming bytes in the flash 22.4.3.3 erase commands erase commands are allowed only on unlocked regions. depending on the flash memory, several commands can be used to erase the flash: ? erase all memory (ea): all memory is erased. the processor must not fetch code from the flash memory. ? erase a memory plane (epl): for dual-plane devices, a ll pages in the memory plane are erased in parallel. the processor must not fetch code from the erased flash memory plane . ? erase pages (epa): 8 or 16 pages are erased in the flash sector selected. the first page to be erased is specified in the farg[15:2] field of the mc_fcr. the first page number must be modulo 8, 16 or 32 depending on the number of pages to erase at the same time. ? erase sector (es): a full me mory sector is erased. sector size de pends on the flash memory. farg must be set with a page number that is in the sector to be erased. if the processor is fetching code from the flash memory while the epa or es command is being performed, the processor accesses will be stalled unt il the epa command is completed. to avoid stalling the processor, the code can be run out of internal sram. 32 bits wide ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c ff ff ff ff ff ff ff ff address space for page n step 1: flash array after programming first byte (0xaa) 64-bit used at address 0xx00 (write latch buffer + wp) ff ff ff ff xx xx xx xx xx xx xx aa 32 bits wide ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c ff ff ff ff xx xx xx xx xx xx xx aa step 2: flash array after programming second byte (0x55) 64-bit used at address 0xx08 (write latch buffer + wp) xx xx xx xx xx xx xx 55 note: the byte location shown here is for example only, it can be any byte location within a 64-bit word. 4 x 32 bits = 1 flash word 4 x 32 bits = 1 flash word
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 432 the erase sequence is: 1. erase starts as soon as one of the erase comman ds and the farg field are written in eefc_fcr. ? for the epa command, the two lowest bits of the fa rg field define the number of pages to be erased (farg[1:0]): 2. when programming is completed, the bit eefc_fsr.fr dy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. three errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? lock error: at least one page to be erased belongs to a locked region. the erase command has been refused, no page has been erased. a command must be ru n previously to unlock the corresponding region. ? flash error: at the end of the programming, the eraseverify test of the flash memory has failed. 22.4.3.4 lock bit protection lock bits are associated with several pages in the embedded flash memory plane. this defines lock regions in the embedded flash memory plane. they prevent writing/erasing protected pages. the lock sequence is: 1. the set lock bit (slb) command and a page number to be protected are written in eefc_fcr. 2. when the locking completes, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. 3. the result of the slb command can be checked running a get lock bit (glb) command. note: the value of the farg argument pa ssed together with slb command must not exceed the higher lock bit index available in the product. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eras everify or writeverify test of the flash memory has failed. it is possible to clear lock bits previously set. then the locked region can be erased or programmed. the unlock sequence is: 1. the clear lock bit (clb) command and a page number to be unprotected are written in eefc_fcr. 2. when the unlock completes, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. note: the value of the farg argument pa ssed together with clb command must not exceed the higher lock bit index available in the product. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eras everify or writeverify test of the flash memory has failed. the status of lock bits can be returned by the eefc. the get lock bit status sequence is: table 22-4. farg field for epa command farg[1:0] number of pages to be erased with epa command 0 4 pages (only valid for small 8 kb sectors) 1 8 pages 2 16 pages 3 32 pages (not valid for small 8 kb sectors)
433 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1. the get lock bit (glb) command is written in eefc_fcr. the farg field is meaningless. 2. lock bits can be read by the software application in eefc_frr. the first word read corresponds to the 32 first lock bits, next reads providing the next 32 lock bits as long as it is meaningful. extra reads to eefc_frr return 0. for example, if the third bit of the first word read in eefc_frr is set, then the third lock region is locked. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eras everify or writeverify test of the flash memory has failed. note: access to the flash in read is permitted when a set, clear or get lock bit command is performed. 22.4.3.5 gpnvm bit gpnvm bits do not interfere with the embedded flash me mory plane. refer to specific product details for information on gpnvm bit action. the set gpnvm bit sequence is: 1. start the set gpnvm bit (sgpb) command by writing eefc_fcr with the sgpb command and the number of the gpnvm bits to be set. 2. when the gpnvm bit is set, the bit eefc_fsr.frdy ri ses. if an interrupt was enabled by setting the bit eefc_fmr.frdy, the interrup t line of the interrupt controller is activated. 3. the result of the sgpb command can be checke d by running a get gpnvm bit (ggpb) command. note: the value of the farg argument pa ssed together with sgpb command must not exceed the higher gpnvm index available in the product. flash data content is not altered if farg exceeds the limi t. command error is detected only if farg is greater than 8. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eras everify or writeverify test of the flash memory has failed. it is possible to clear gpnvm bits previo usly set. the clear gpnvm bit sequence is: 1. start the clear gpnvm bit (cgpb) command by writing eefc_fcr with cgpb and the number of the gpnvm bits to be cleared. 2. when the clear completes, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrup t line of the interrupt controller is activated. note: the value of the farg argument passed together with cgpb command must not exceed the higher gpnvm index available in the product. flash data content is not altered if farg exceeds the limi t. command error is detected only if farg is greater than 8. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eras everify or writeverify test of the flash memory has failed. the status of gpnvm bits can be re turned by the eefc. the sequence is: 1. start the get gpnvm bit command by writing eef c_fcr with ggpb. the farg field is meaningless. 2. gpnvm bits can be read by the software application in eefc_frr. the first word read corresponds to the 32 first gpnvm bits, following reads provide the next 32 gpnvm bits as long as it is meaningful. extra reads to eefc_frr return 0. for example, if the third bit of the first word read in eefc_frr is set, then the third gpnvm bit is active. one error can be detected in eefc_fsr after a programming sequence:
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 434 ? command error: a bad keyword has been written in eefc_fcr. note: access to the flash in read is permitted when a set, clear or get gpnvm bit command is performed. 22.4.3.6 calibration bit calibration bits do not interfere with the embedded flash memory plane. the calibration bits cannot be modified. the status of calibration bits are re turned by the eefc. the sequence is: 1. issue the get calib bit command by writing eefc_fcr with gcalb (see table 22-2 ). the farg field is meaningless. 2. calibration bits can be read by the software application in eefc_frr. the first word read corresponds to the first 32 calibration bits. the following reads provide the next 32 calibration bits as lo ng as it is meaningful. extra reads to eefc_frr return 0. the 4/8/12 mhz fast rc oscillator is calib rated in production. this calibration can be read thro ugh the get calib bit command. the table below shows the bit implementation for each frequency: the rc calibration for the 4 mhz is set to ?1000000?. 22.4.3.7 security bit protection when the security is enabled, access to the flash, either through the jtag/swd interface or through the fast flash programming interface, is forbidden. this ensures the confidentiality of the c ode programmed in the flash. the security bit is gpnvm0. disabling the security bit can only be achieved by asserting the erase pin at 1, and after a full flash erase is performed. when the security bit is deactiva ted, all accesses to the flash are permitted. 22.4.3.8 unique identifier each device is programmed with a 2 512-byte unique identi fier. it can be used to generate keys for example. for dual-plane devices, the unique id is accessible on both memory planes. to read the unique identifier, the sequence is: 1. send the start read unique identifier (stui) command by writing eefc_fcr with the stui command. 2. when the unique identifier is ready to be read, the bit eefc_fsr.frdy falls. 3. the unique identifier is located at the address 0x10 00000-0x10003ff, in the firs t 128 bits of the flash memory mapping. 4. to stop the unique identifier mode, the user needs to send the stop read unique identifier (spui) command by writing eefc_fcr with the spui command. 5. when the spui command has been performed, the bit eefc_fsr.frdy rises. if an interrupt was enabled by setting the bit eefc_fmr.frdy , the interrupt line of the inte rrupt controller is activated. note that during the sequence, the software cannot run out of flash or the second plane in case of dual plane. 22.4.3.9 user signature each part contains a user signature of 512 bytes. it can be used for storage. read, write and erase of this area is allowed. to read the user signature, the sequence is as follows: table 22-5. calibra tion bit indexes rc calibration frequency eefc_frr bits 8 mhz output [28?22] 12 mhz output [38?32]
435 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1. send the start read user signature (stus) command by writing eefc_fcr with the stus command. 2. when the user signature is ready to be read, the bit eefc_fsr.frdy falls. 3. the user signature is located in the first 512 byte s of the flash memory mapping, thus, at the address 0x1000000-0x10001ff. 4. to stop the user signature mode, the user needs to send the stop read user signature (spus) command by writing eefc_fcr with the spus command. 5. when the spui command has been performed, the bit eefc_fsr.frdy rises. if an interrupt was enabled by setting the bit eefc_fmr.frdy , the interrupt line of the inte rrupt controller is activated. note that during the sequence, the software cannot run out of flash or the second plane in case of dual plane. one error can be detected in eefc_fsr after this sequence: ? command error: a bad keyword has been written in eefc_fcr. to write the user signature, the sequence is: 1. write the full page, at any page address, within the internal memory area address space. 2. send the write user signature (wus) command by writing eefc_f cr with the wus command. 3. when programming is completed, the bit eefc_fsr.fr dy rises. if an interrupt has been enabled by setting the bit i eefc_fmr.frdy, the corresponding interrupt line of the interrupt controller is activated. two errors can be detected in eefc_fsr after this sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the writeverify test of the flash memory has failed. to erase the user signature, the sequence is: 1. send the erase user signature (eus) command by writing eefc_fcr with the eus command. 2. when programming is completed, the bit eefc_fsr.fr dy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the corresponding interrupt line of the interrupt controller is activated. two errors can be detected in eefc_fsr after this sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eraseverify test of the flash memory has failed. 22.4.3.10ecc errors and corrections the flash embeds an ecc module able to correct one uniq ue error and able to detect two errors. the errors are detected while a read access is performed into memory array and stored in eefc_fsr (see section 22.5.3 ?eefc flash status register? on page 440 ). the error report is kept until eefc_fsr is read. there is one flag for a unique error on lower half part of the flash word (64 lsb) and one flag for the upper half part (msb). the multiple errors are reported in the same way. due to the anticipation mechanism to improve bandwidth throughput on instruction fetch, a reported error can be located in the next sequential flash word compared to the location of the instruction being executed, which is located in the previously fetched flash word. if a software routine processes the e rror detection independently from the main software routine, the entire flash located software must be rewritten because there is no storage of the error location. if only a software routine is running to program and ch eck pages by reading eefc_fsr, the situation differs from previous case. performing a check for ecc unique errors just after page programming completion involves a read of the newly programmed page. this read sequence is view ed as data accesses and is not optimized by the flash controller. thus, in case of unique error, only the current page must be reprogrammed.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 436 22.5 enhanced embedded flash cont roller (eefc) user interface the user interface of the embedded flash controller (eefc) is integrated within the system controller with base address 0x400e0a00 . table 22-6. register mapping offset register name access reset state 0x00 eefc flash mode register eefc_fmr read/write 0x0400_0000 0x04 eefc flash command register eefc_fcr write-only ? 0x08 eefc flash status register eefc_fsr read-only 0x00000001 0x0c eefc flash result register eefc_frr read-only 0x0 0x10?0x14 reserved ? ? ? 0x18?0xe4 reserved ? ? ?
437 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 22.5.1 eefc flash mode register name: eefc_fmr address: 0x400e0a00 access: read/write ? frdy: flash ready interrupt enable 0: flash ready does not generate an interrupt. 1: flash ready (to accept a new command) generates an interrupt. ? fws: flash wait state this field defines the number of wait states for read and write operations: number of cycles for read/w rite operations = fws + 1 ? scod: sequential code optimization disable 0: the sequential code optimization is enabled. 1: the sequential code optimization is disabled. no flash read should be done during change of this register. ? fam: flash access mode 0: 128-bit access in read mode only, to enhance access speed. 1: 64-bit access in read mode on ly, to enhance power consumption. no flash read should be done during change of this register. ? cloe: code loop optimization enable 0: the opcode loop optimization is disabled. 1: the opcode loop optimization is enabled. no flash read should be done during change of this register. 31 30 29 28 27 26 25 24 ?????c l o e?f a m 23 22 21 20 19 18 17 16 ???????s c o d 15 14 13 12 11 10 9 8 ???? f w s 76543210 ???????f r d y
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 438 22.5.2 eefc flash command register name: eefc_fcr address: 0x400e0a04 access: write-only ? fcmd: flash command 31 30 29 28 27 26 25 24 fkey 23 22 21 20 19 18 17 16 farg 15 14 13 12 11 10 9 8 farg 76543210 fcmd value name description 0x00 getd get flash descriptor 0x01 wp write page 0x02 wpl write page and lock 0x03 ewp erase page and write page 0x04 ewpl erase page and write page then lock 0x05 ea erase all 0x06 epl erase plane 0x07 epa erase pages 0x08 slb set lock bit 0x09 clb clear lock bit 0x0a glb get lock bit 0x0b sgpb set gpnvm bit 0x0c cgpb clear gpnvm bit 0x0d ggpb get gpnvm bit 0x0e stui start read unique identifier 0x0f spui stop read unique identifier 0x10 gcalb get calib bit 0x11 es erase sector 0x12 wus write user signature 0x13 eus erase user signature 0x14 stus start read user signature 0x15 spus stop read user signature
439 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? farg: flash command argument ? fkey: flash writing protection key getd, glb, ggpb, stui, spui, gcalb, wus, eus, stus, spus, ea commands requiring no argument, including erase all command farg is meaningless, must be written with 0 epl erase plane command farg must be written with a page number that is in the memory plane to be erased. es erase sector command farg must be written with any page number within the sector to be erased epa erase pages command farg[1:0] defines the number of pages to be erased the start page must be written in farg[15:2]. farg[1:0] = 0: four pages to be erased. farg[15:2] = page_number modulo 4 farg[1:0] = 1: eight pages to be erased. farg[15:2] = page_number modulo 8 farg[1:0] = 2: sixteen pages to be er ased. farg[15:2] = page_number modulo 16 farg[1:0] = 3: thirty-two pages to be erased. farg[15:2] = page_number modulo 32 refer to table 22-4 on page 432 . wp, wpl, ewp, ewpl programming commands farg must be written with the page number to be programmed slb, clb lock bit commands farg defines the page number to be locked or unlocked sgpb, cgpb gpnvm commands farg defines the gpnvm number to be programmed value name description 0x5a passwd the 0x5a value enables the command defined by the bi ts of the register. if the field is written with a different value, the write is not performed and no action is started.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 440 22.5.3 eefc flash status register name: eefc_fsr address: 0x400e0a08 access: read-only ? frdy: flash ready status 0: the eefc is busy. 1: the eefc is ready to start a new command. when set, this flag triggers an interrupt if the frdy flag is set in eefc_fmr. this flag is automatically cleared when the eefc is busy. ? fcmde: flash command error status 0: no invalid commands and no bad keywords were written in eefc_fmr. 1: an invalid command and/or a bad keyword was/were written in eefc_fmr. this flag is automatically cleared when eef c_fsr is read or eefc_fcr is written. ? flocke: flash lock error status 0: no programming/erase of at least one locked region has happened since the last read of eefc_fsr. 1: programming/erase of at least one locked regi on has happened since the last read of eefc_fsr. this flag is automatically cleared when eef c_fsr is read or eefc_fcr is written. ? flerr: flash error status 0: no flash memory error occurred at the end of prog ramming (eraseverify or writeverify test has passed). 1: a flash memory error occurred at the end of programming (eraseverify or writeverify test has failed). ? ueccelsb: unique ecc error on lsb part of the memory flash data bus 0: no unique error detected on 64 lsb data bus of the flash memory since the last read of eefc_fsr. 1: one unique error detected but corrected on 64 lsb data bus of the flash memory since the last read of eefc_fsr. ? meccelsb: multiple ecc error on lsb part of the memory flash data bus 0: no multiple error detected on 64 lsb part of the flash memory data bus since the last read of eefc_fsr. 1: multiple errors detected and not corrected on 64 lsb pa rt of the flash memory data bus since the last read of eefc_fsr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????m e c c e m s b u e c c e m s b m e c c e l s bu e c c e l s b 15 14 13 12 11 10 9 8 ???????? 76543210 ????f l e r rf l o c k ef c m d ef r d y
441 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? ueccemsb: unique ecc error on msb part of the memory flash data bus 0: no unique error detected on 64 msb data bus of the flash memory since the last read of eefc_fsr. 1: one unique error detected but corrected on 64 msb data bu s of the flash memory since the last read of eefc_fsr. ? meccemsb: multiple ecc error on msb part of the memory flash data bus 0: no multiple error detected on 64 msb part of the flash memory data bus since the last read of eefc_fsr. 1: multiple errors detected and not corrected on 64 msb part of the flash memory data bus since the last read of eefc_fsr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 442 22.5.4 eefc flash result register name: eefc_frr address: 0x400e0a0c access: read-only ? fvalue: flash result value the result of a flash command is returned in this register. if the size of the result is grea ter than 32 bits, then the next resulting value is accessible at the next register read. 31 30 29 28 27 26 25 24 fvalue 23 22 21 20 19 18 17 16 fvalue 15 14 13 12 11 10 9 8 fvalue 76543210 fvalue
443 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 23. fast flash programming interface (ffpi) 23.1 description the fast flash programming interface (ffpi) provides parallel high-volume programming using a standard gang programmer. the parallel interface is fully handshaked and the device is considered to be a standard eeprom. additionally, the parallel protocol offers an optimize d access to all the embedded flash functionalities. although the fast flash programming mode is a dedicated mode for high volu me programming, this mode is not designed for in-situ programming. 23.2 embedded characteristics ? programming mode for high-volume flash programming using gang programmer ? offers read and write access to the flash memory plane ? enables control of lock bits and general-purpose nvm bits ? enables security bit activation ? disabled once security bit is set ? parallel fast flash programming interface ? provides an 16-bit parallel interface to program the embedded flash ? full handshake protocol
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 444 23.3 parallel fast flash programming 23.3.1 device configuration in fast flash programming mode, the device is in a specific test mode. only a ce rtain set of pins is significant. the rest of the pios are used as inputs wit h a pull-up. the crystal osc illator is in bypass mode. other pins must be left unconnected. figure 23-1. parallel programming interface ncmd pgmncmd rdy pgmrdy noe pgmnoe nvalid pgmnvalid mode[3:0] pgmm[3:0] data[15:0] pgmd[15:0] xin tst vddio pgmen0 pgmen1 0 - 50mhz vddio vddcore vddio vddpll vddbu gnd vddio table 23-1. signal description list signal name function type active level comments power vddio i/o lines power supply power ? ? vddcore core power supply power ? ? vddpll pll power supply power ? ? gnd ground ground ? ? clocks xin main clock input. this input can be tied to gnd. in this case, the device is cl ocked by the internal rc oscillator. input ? 32 khz to 50 mhz test tst test mode select input high must be connected to vddio pgmen0 test mode select input high must be connected to vddio pgmen1 test mode select input high must be connected to vddio pio pgmncmd valid command available input low pulled-up input at reset
445 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 23.3.2 signal names depending on the mode settings, data is latched in different internal registers. when mode is equal to cmde, then a new command (strobe d on data[15:0] signals) is stored in the command register. pgmrdy 0: device is busy 1: device is ready for a new command output high pulled-up input at reset pgmnoe output enable (active high) i nput low pulled-up input at reset pgmnvalid 0: data[15:0] is in input mode 1: data[15:0] is in output mode output low pulled-up input at reset pgmm[3:0] specifies data type (see table 23-2 ) input ? pulled-up input at reset pgmd[15:0] bi-directional data bus input/output ? pulled-up input at reset table 23-1. signal description list (continued) signal name function type active level comments table 23-2. mode coding mode[3:0] symbol data 0000 cmde command register 0001 addr0 address register lsbs 0010 addr1 ? 0101 data data register default idle no register table 23-3. command bit coding data[15:0] symbol command executed 0x0011 read read flash 0x0012 wp write page flash 0x0022 wpl write page and lock flash 0x0032 ewp erase page and write page 0x0042 ewpl erase page and write page then lock 0x0013 ea erase all 0x0014 slb set lock bit 0x0024 clb clear lock bit 0x0015 glb get lock bit 0x0034 sgpb set general purpose nvm bit 0x0044 cgpb clear general purpose nvm bit 0x0025 ggpb get general purpose nvm bit 0x0054 sse set security bit
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 446 23.3.3 entering programming mode the following algorithm puts the device in parallel programming mode: ? apply the supplies as described in table 23-1 . ? apply xin clock within t por_reset if an external clock is available. ? wait for t por_reset ? start a read or write handshaking. note: after reset, the device is clocked by the internal rc o scillator. before clearing rdy signal, if an external clock ( > 32 khz) is connected to xin, then the device switches on the external clock. else, xin inpu t is not considered. a higher frequency on xin speeds up the programmer handshake. 23.3.4 programmer handshaking a handshake is defined for read and write operations. when the device is ready to start a new operation (rdy signal set), the programmer starts the handshake by clearing the ncmd signal. the handshaking is achieved once ncmd signal is high and rdy is high. 23.3.4.1 write handshaking for details on the write handshaking sequence, refer to figure 23-2 and table 23-4 . figure 23-2. parallel programming timing, write sequence 0x0035 gse get security bit 0x001f wram write memory 0x001e gve get version table 23-3. command bit coding (continued) data[15:0] symbol command executed ncmd rdy noe nvalid data[15:0] mode[3:0] 1 2 3 4 5 table 23-4. write handshake step programmer action device action data i/o 1 sets mode and data signals waits for ncmd low input 2 clears ncmd signal latch es mode and data input 3 waits for rdy low clears rdy signal input
447 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 23.3.4.2 read handshaking for details on the read handshaking sequence, refer to figure 23-3 and table 23-5 . figure 23-3. parallel programming timing, read sequence 4 releases mode and data signals executes command and polls ncmd high input 5 sets ncmd signal executes command and polls ncmd high input 6 waits for rdy high sets rdy input table 23-4. write handshake step programmer action device action data i/o ncmd rdy noe nvalid data[15:0] mode[3:0] 1 2 3 4 5 6 7 9 8 addr adress in z data out 10 11 xin 12 13 table 23-5. read handshake step programmer action device action data i/o 1 sets mode and data signals waits for ncmd low input 2 clears ncmd signal latch mode and data input 3 waits for rdy low clears rdy signal input 4 sets data signal in tristate waits for noe low input 5 clears noe signal ? tristate 6 waits for nvalid low sets data bus in output mode and outputs the flash contents. output 7 ? clears nvalid signal output 8 reads value on data bus waits for noe high output 9 sets noe signal ? output 10 waits for nvalid high sets data bus in input mode x 11 sets data in output mode sets nvalid signal input 12 sets ncmd signal waits for ncmd high input 13 waits for rdy high sets rdy signal input
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 448 23.3.5 device operations several commands on the flash memory are available. these commands are summarized in table 23-3 on page 445 . each command is driven by the programmer through the parallel interface running several read/write handshaking sequences. when a new command is executed, the previous one is automatically achieved. thus, chaining a read command after a write automatically flushes the load buffer in the flash. 23.3.5.1 flash read command this command is used to read the contents of the flash memory. the read comm and can start at any valid address in the memory plane and is optimized for cons ecutive reads. read handshaki ng can be chained; an internal address buffer is automatically increased. 23.3.5.2 flash write command this command is used to wr ite the flash contents. the flash memory plane is organized into several pages. data to be written are stored in a load buffer that corresponds to a flash memory page. the load buffer is automatically flushed to the flash: ? before access to any page other than the current one ? when a new command is validated (mode = cmde) the write page command (wp) is optimized for consecutive writes. write handshak ing can be chained; an internal address buffer is automatically increased. table 23-6. read command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde read 2 write handshaking addr0 memory address lsb 3 write handshaking addr1 memory address 4 read handshaking data *memory address++ 5 read handshaking data *memory address++ ... ... ... ... n write handshaking addr0 memory address lsb n+1 write handshaking addr1 memory address n+2 read handshaking data *memory address++ n+3 read handshaking data *memory address++ ... ... ... ... table 23-7. write command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde wp or wpl or ewp or ewpl 2 write handshaking addr0 memory address lsb 3 write handshaking addr1 memory address 4 write handshaking data *memory address++ 5 write handshaking data *memory address++ ... ... ... ... n write handshaking addr0 memory address lsb
449 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the flash command write page and lock (wpl) is equivalent to the flash wr ite command. however, the lock bit is automatically set at the end of the flash write operat ion. as a lock region is composed of several pages, the programmer writes to the first pages of the lock region using flash write commands and writes to the last page of the lock region using a flash write and lock command. the flash command erase page and write (ewp) is equivalent to the flash write command. however, before programming the load buffer, the page is erased. the flash command erase page and write the lock (ewpl) combines ewp and wpl commands. 23.3.5.3 flash full erase command this command is used to erase the flash memory planes. all lock regions must be unlocked before the full erase command by using the clb command. otherwise, the erase command is aborted and no page is erased. 23.3.5.4 flash lock commands lock bits can be set using wpl or ewpl co mmands. they can also be set by using the set lock command (slb) . with this command, several lock bits can be activated. a bit mask is provided as argument to the command. when bit 0 of the bit mask is set, then the first lock bit is activated. in the same way, the clear lock command (clb) is used to clear lock bits. lock bits can be read using get lock bit command (glb) . the n th lock bit is active when the bit n of the bit mask is set.. n+1 write handshaking addr1 memory address n+2 write handshaking data *memory address++ n+3 write handshaking data *memory address++ ... ... ... ... table 23-7. write co mmand (continued) step handshake sequence mode[3:0] data[15:0] table 23-8. full erase command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde ea 2 write handshaking data 0 table 23-9. set and clear lock bit command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde slb or clb 2 write handshaking data bit mask table 23-10. get lock bit command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde glb 2 read handshaking data lock bit mask status 0 = lock bit is cleared 1 = lock bit is set
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 450 23.3.5.5 flash general-purpose nvm commands general-purpose nvm bits (gp nv m bits) can be set using the set gpnvm command (sgpb) . this command also activates gp nvm bits. a bit mask is provided as argu ment to the command. when bit 0 of the bit mask is set, then the first gp nvm bit is activated. in the same way, the clear gpnvm command (cgpb) is used to clear general-purpose nvm bits. the general- purpose nvm bit is deactivated when the corres ponding bit in the pattern value is set to 1. general-purpose nvm bits can be read using the get gpnvm bit command (ggpb) . the n th gp nvm bit is active when bit n of the bit mask is set.. 23.3.5.6 flash security bit command a security bit can be set using the set security bit command (sse). once the security bit is active, the fast flash programming is disabled. no other command can be run. an event on the erase pin can erase the security bit once the contents of the flash have been erased. once the security bit is set, it is not possible to access ffp i. the only way to erase the security bit is to erase the flash. in order to erase the flash, the user must perform the following: ? power-off the chip ? power-on the chip with tst = 0 ? assert erase during a period of more than 220 ms ? power-off the chip then it is possible to return to ffpi mode and check that flash is erased. table 23-11. set/clear gp nvm command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde sgpb or cgpb 2 write handshaking data gp nvm bit pattern value table 23-12. get gp nvm bit command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde ggpb 2 read handshaking data gp nvm bit mask status 0 = gp nvm bit is cleared 1 = gp nvm bit is set table 23-13. set security bit command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde sse 2 write handshaking data 0
451 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 23.3.5.7 memory write command this command is used to perform a write access to any memory location. the memory write command (wram) is optimized for consecutive writes. write handshaking can be chained; an internal address buffer is automatically increased. 23.3.5.8 get version command the get version (gve) command retrieves the ve rsion of the ffpi interface. table 23-14. write command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde wram 2 write handshaking addr0 memory address lsb 3 write handshaking addr1 memory address 4 write handshaking data *memory address++ 5 write handshaking data *memory address++ ... ... ... ... n write handshaking addr0 memory address lsb n+1 write handshaking addr1 memory address n+2 write handshaking data *memory address++ n+3 write handshaking data *memory address++ ... ... ... ... table 23-15. get version command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde gve 2 read handshaking data version
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 452 24. cortex m cache controller (cmcc) 24.1 description the cortex m cache controller (cmcc) is a 4-way set associative unified cache cont roller. it integrates a controller, a tag directory, data memory, metadata memory and a configuration interface. 24.2 embedded characteristics ? physically addressed and physically tagged ? l1 data cache set to 2 kbytes ? l1 cache line size set to 16 bytes ? l1 cache integrates 32-bit bus master interface ? unified direct mapped cache architecture ? unified 4-way set associ ative cache architecture ? write through cache operations, read allocate ? round robin victim selection policy ? event monitoring, with one programmable 32-bit counter ? configuration registers accessible through cortex m private peripheral bus ? cache interface includes cache maintenance operations registers 24.3 block diagram figure 24-1. block diagram cache controller metadata ram data ram tag ram ram interf ace cortex m interf ace memory interf ace registers interf ace apb interf ace cortex m memory interf ace bus sys tem memory bus
453 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 24.4 functional description 24.4.1 cache operation on reset, the cache controller data entries are all invalidat ed and the cache is enabled. the cache is transparent to processor operations. the cache controller is activated with its configuration registers. the configuration interface is memory mapped in the private peripheral bus. the cache must always be enabled, even if the code is running out of a non-cached region. when the cache is disabled, the accesses to the cache on its slave port are ?forwarded? to the master port. in this case, there are two simultaneous accesses on the matrix: one on a non-cached region, and another ?dummy? access on the cache master port. these two accesses can slow down the system due to the wait error introduction on the cache master port. 24.4.2 cache maintenance if the contents seen by the cache has changed, the user needs to invalidate the cache entries. it can be done line by line or for all cache entries. 24.4.2.1 cache invalidate by line operation when an invalidate by line command is issued the cache controller resets the valid bit information of the decoded cache line. as the line is no longer valid the replacement counter points to that line. use the following sequence to invalidate one line of cache: 1. disable the cache controller, writing 0 to the cen bit of the cmcc_ctrl register. 2. check csts bit of the cmcc_sr to verify that the cache is su ccessfully disabled. 3. perform an invalidate by line wr iting the bit set {index, way} in the maintenance register 1 (cmcc_maint1). 4. enable the cache controller, writing 1 to the cen bit of the cmcc_ctrl register. 24.4.2.2 cache invalidate all operation to invalidate all cache entries, write a 1 to the in vall bit of the maintenance register 0 (cmcc_maint0). 24.4.3 cache perfo rmance monitoring the cortex m cache controller includes a programmable 32-bit monitor counter. the monitor can be configured to count the number of clock cycles, the number of data hits or the number of instruction hits. use the following sequence to activate the counter: 1. configure the monitor counter, writing the mode field of the monitor configuration register (cmcc_mcfg). 2. enable the counter, writing one to the menable bit of the monitor enable register (cmcc_men). 3. if required, reset the counter, writing one to the sw rst bit of the monitor control register (cmcc_mctrl). 4. check the value of the monitor counter, reading event_cnt field of the cmcc_sr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 454 24.5 cortex m cache controll er (cmcc) user interface table 24-1. register mapping offset register name access reset 0x00 cache controller type register cmcc_type read-only 0x000011d7 0x04 reserved ? ? ? 0x08 cache controller control register cmcc_ctrl write-only ? 0x0c cache controller status register cmcc_sr read-only 0x00000001 0x10?0x1c reserved ? ? ? 0x20 cache controller maintenance register 0 cmcc_maint0 write-only ? 0x24 cache controller maintenance register 1 cmcc_maint1 write-only ? 0x28 cache controller monitor configurat ion register cmcc_mcfg read/write 0x00000000 0x2c cache controller monitor enable register cmcc_men read/write 0x00000000 0x30 cache controller monitor control register cmcc_mctrl write-only ? 0x34 cache controller monitor status register cmcc_msr read-only 0x00000000 0x38?0xfc reserved ? ? ?
455 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 24.5.1 cache controller type register name: cmcc_type address: 0x4007c000 (0), 0x48018000 (1) access: read-only ? randp: random selection policy supported 0: random victim selection is not supported. 1: random victim sele ction is supported. ? lrup: least recently used policy supported 0: least recently used policy is not supported. 1: least recently used policy is supported. ? rrp: random selection policy supported 0: random selection policy is not supported. 1: random selection policy is supported. ? waynum: number of ways ? lckdown: lock down supported 0: lock down is not supported. 1: lock down is supported. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?c l s i z ec s i z e 76543210 lckdown waynum rrp lrup randp ? ? value name description 0 dmapped direct mapped cache 1 arch2way 2-way set associative 2 arch4way 4-way set associative 3 arch8way 8-way set associative
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 456 ? csize: data cache size ? clsize: cache line size value name description 0 csize_1kb data cache size 1 kbyte 1 csize_2kb data cache size 2 kbytes 2 csize_4kb data cache size 4 kbytes 3 csize_8kb data cache size 8 kbytes value name description 0 clsize_1kb cache line size 4 bytes 1 clsize_2kb cache line size 8 bytes 2 clsize_4kb cache line size 16 bytes 3 clsize_8kb cache line size 32 bytes
457 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 24.5.2 cache controller control register name: cmcc_ctrl address: 0x4007c008 (0), 0x48018008 (1) access: write-only ? cen: cache controller enable 0: when set to 0, this bit disables the cache controller. 1: when set to 1, this bit enables the cache controller. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????c e n
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 458 24.5.3 cache controller status register name: cmcc_sr address: 0x4007c00c (0), 0x4801800c (1) access: read-only ? csts: cache controller status 0: when read as 0, this bit indicates that the cache controller is disabled. 1: when read as 1, this bit indicate s that the cache controller is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????c s t s
459 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 24.5.4 cache controller maintenance register 0 name: cmcc_maint0 address: 0x4007c020 (0), 0x48018020 (1) access: write-only ? invall: cache controller invalidate all 0: no effect. 1: when set to 1, this bit invalidates all cache entries. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????i n v a l l
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 460 24.5.5 cache controller maintenance register 1 name: cmcc_maint1 address: 0x4007c024 (0), 0x48018024 (1) access: write-only ? index: invalidate index this field indicates the cache line that is being invalidated. the size of the index field depends on the cache size: ? for 2 kbytes: 5 bits ? for 4 kbytes: 6 bits ? for 8 kbytes: 7 bits, and so on ? way: invalidate way 31 30 29 28 27 26 25 24 w a y ?????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????i n d e x 76543210 i n d e x ???? value name description 0 way0 way 0 is selection for index invalidation 1 way1 way 1 is selection for index invalidation 2 way2 way 2 is selection for index invalidation 3 way3 way 3 is selection for index invalidation
461 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 24.5.6 cache controller moni tor configuration register name: cmcc_mcfg address: 0x4007c028 (0), 0x48018028 (1) access: write-only ? mode: cache controller monitor counter mode 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????? m o d e value name description 0 cycle_count cycle counter 1 ihit_count instruction hit counter 2 dhit_count data hit counter
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 462 24.5.7 cache controller monitor enable register name: cmcc_men address: 0x4007c02c (0), 0x4801802c (1) access: write-only ? menable: cache controller monitor enable 0: when set to 0, the monitor counter is disabled. 1: when set to 1, the monitor counter is activated. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????m e n a b l e
463 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 24.5.8 cache controller monitor control register name: cmcc_mctrl address: 0x4007c030 (0), 0x48018030 (1) access: write-only ? swrst: monitor 0: no effect. 1: when set to 1, this bit rese ts the event counter register. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????s w r s t
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 464 24.5.9 cache controller monitor status register name: cmcc_msr address: 0x4007c034 (0), 0x48018034 (1) access: read-only ? event_cnt: monitor event counter 31 30 29 28 27 26 25 24 event_cnt 23 22 21 20 19 18 17 16 event_cnt 15 14 13 12 11 10 9 8 event_cnt 76543210 event_cnt
465 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 25. interprocessor communication (ipc) 25.1 description the interprocessor communication (ipc) module has 32 interrupt sources. each source has a set of enable, disable, clear, set, mask and status registers. the interrupt sources are ored, and the ipc interrupt output line is connected to the interrupt controller input. 25.2 block diagram figure 25-1. ipc block diagram figure 25-2. dual core ipc implementation apb arm core ipc_ipr irq0 ipc_ipr irq1 ipc_ipr irq31 thirty-two sources irqn ipc nvic1 nvic0 ipc0 ipc1 async ahb-ahb bridge ahb matrix (mx1) ahb to apb bridge 1 ahb matrix (mx0) ahb to apb bridge 0 to nvic1 to nvic0 core 1 metrology core (cortex-m4f) core 0 application core (cortex-m4)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 466 25.3 product dependencies 25.3.1 power management the interprocessor communication module is not continuously clocked. the ipc interface is clocked through the power management controller (pmc), therefore the program mer must first configure the pmc to enable the ipc clock. 25.3.2 interrupt line the ipc module has an interrupt line connected to th e interrupt controller. handling interrupts requires programming the interrupt controlle r before configuring the ipc. 25.4 functional description 25.4.1 interrupt sources 25.4.1.1 interrupt generation interrupt sources can be individually generated by writ ing respectively the ipc_is cr and ipc_iccr registers. 25.4.1.2 interrupt source control each interrupt source (irq0 to irq31) can be enabled or disabled by using the command registers: ipc_iecr (interrupt enable command register) and ipc_idcr (interrupt disable command register). this set of registers conducts enabling or disabling of an instruction. the inte rrupt mask can be read in the ipc_imr register. all ipc interrupts can be enabled/disabled, thus configuring the ipc interrupt mask register. each pending and unmasked ipc interrupt asserts the ipc ou tput interrupt line. a disabled interrupt does not affect servicing of other interrupts. 25.4.1.3 interrupt status the ipc_iecr and ipc_idcr registers are used to determine which interrupt sour ces are active/inhibited to generate an interrupt output. the ipc_imr register is a status of the interrupt so urce selection (a result from write into the ipc_iecr and ipc_idcr registers). the ipc_is cr and ipc_iccr registers are used to activate/inhibit interrupt sources. the ipc_ipr register is a status regi ster giving active interrupt sources. the ipc_isr register reports which interrupt source(s) is(are) currently asserting an interrupt output. ipc_isr is basically equivalent to an and between the ipc_ipr and ipc_imr registers. table 25-1. peripheral ids instance id ipc0 31 ipc1 39
467 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 25-3. interrupt input stage clear set interrupt controller ipc_ipr irq0 ipc_isr irq0 ipc_idcr irq0 ipc_imr irq0 ipc_iecr irq0 ipc_iccr irq0 ipc_iscr irq0 clear set clear set ipc_ipr irq31 ipc_isr irq31 ipc_idcr irq31 ipc_imr irq31 ipc_iecr irq31 ipc_iccr irq31 ipc_iscr irq31 clear set
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 468 25.5 inter-processor communication (ipc) user interface table 25-2. register mapping offset register name access reset 0x0000 interrupt set command register ipc_iscr write-only ? 0x0004 interrupt clear command register ipc_iccr write-only ? 0x0008 interrupt pending register ipc_ipr read-only 0x0 0x000c interrupt enable command register ipc_iecr write-only ? 0x0010 interrupt disable command register ipc_idcr write-only ? 0x0014 interrupt mask register ipc_imr read-only 0x0 0x0018 interrupt status register ipc_isr read-only 0x0
469 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 25.5.1 ipc interrupt set command register name: ipc_iscr address: 0x4004c000 (0), 0x48014000 (1) access: write-only ? irq0-irq31: interrupt set 0: no effect. 1: sets the corresponding interrupt. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 470 25.5.2 ipc interrupt clear command register name: ipc_iccr address: 0x4004c004 (0), 0x48014004 (1) access: write-only ? irq0-irq31: interrupt clear 0: no effect. 1: clears the corresponding interrupt. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
471 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 25.5.3 ipc interrupt pending register name: ipc_ipr address: 0x4004c008 (0), 0x48014008 (1) access: read-only ? irq0-irq31: interrupt pending 0: the corresponding interrupt is not pending. 1: the corresponding interrupt is pending. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 472 25.5.4 ipc interrupt enable command register name: ipc_iecr address: 0x4004c00c (0), 0x4801400c (1) access: write-only ? irq0-irq31: interrupt enable 0: no effect. 1: enables the corresponding interrupt. 25.5.5 ipc interrupt disable command register name: ipc_idcr address: 0x4004c010 (0), 0x48014010 (1) access: write-only ? irq0-irq31: interrupt disable 0: no effect. 1: disables the corresponding interrupt. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
473 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 25.5.6 ipc interrupt mask register name: ipc_imr address: 0x4004c014 (0), 0x48014014 (1) access: read-only reset: 0x0 ? irq0-irq31: interrupt mask 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 474 25.5.7 ipc interrupt status register name: ipc_isr access: read-only reset: 0x0 ? irq0-irq31: current interrupt identifier 0: the corresponding interrupt source is not currently asserting the interrupt output. 1: the corresponding interrupt source is currently asserting the interrupt output. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
475 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 26. bus matrix (matrix) 26.1 description the bus matrix implements a multi-layer ahb, based on the ahb-lite pr otocol, that enables parallel access paths between multiple ahb masters and slaves in a system, thus increasing the overall bandwidth. the bus matrix interconnects ahb masters to ahb slaves. the normal latency to connec t a master to a slave is one cycle except for the default master of the accessed slave wh ich is connected directly (zero cycle latency). 26.2 embedded characteristics ? one decoder for each master ? support for long bursts of 32, 64 and 128 beats and up to the 256-beat word burst ahb limit ? enhanced programmable mixed arbitration for each slave ? round-robin ? fixed priority ? latency quality of service ? programmable default master for each slave ? no default master ? last accessed default master ? fixed default master ? deterministic maximum access latency for masters ? zero or one cycle arbitration laten cy for the first access of a burst ? bus lock forwarding to slaves ? master number forwarding to slaves ? write protection of user interface registers
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 476 26.2.1 matrix 0 26.2.1.1 matrix 0 masters the bus matrix 0, which corresponds to the sub-system 0 (core 0 - cm4p0), manages the masters listed in table 26-1 . each master can perform an access to an available slave concurrently with other masters. each master has its own specifically-def ined decoder. in order to simplify the addressing, all the masters have the same decodings. 26.2.1.2 matrix 0 slaves the bus matrix manages the slaves listed in table 26-2 . each slave has its own arbiter providing a dedicated arbitration per slave. table 26-1. list of bus matrix masters master 0 cortex-m4 instruct ion/data (cm4p0 i/d bus) master 1 cortex-m4 system (cm4p0 s bus) master 2 peripheral dma controller 0 (pdc0) master 3 integrity check module (icm) master 4 matrix1 master 5 ebi matrix1 master 6 cmcc0 table 26-2. list of bus matrix slaves slave 0 internal sram0 slave 1 internal rom slave 2 internal flash slave 3 external bus interface slave 4 peripheral bridge 0 slave 5 cpkcc ram and rom slave 6 matrix1 slave 7 cmcc0
477 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 26.2.1.3 master to slave access (matrix 0) table 26-3 gives valid paths for master to slave access on ma trix 0. the paths shown as ?-? are forbidden or not wired, e.g. access from the cortex -m4 s bus to the internal rom. 26.2.1.4 accesses through matrix 0 ? cm4p0 i/d bus access to: ? flash, rom ? ebi (0x03000000 to 0x06ffffff) ? flash and ebi through cache controller cmcc0 (respectively through 0x11000000 to 0x11ffffff and 0x13000000 to 0x16ffffff) ? cmp4p0 s bus access to: ? sram0, sram1 through matrix1, sram2 through matrix1 ? pkcc ? ebi (through 0x60000000 to 0x63ffffff, 0xa0000000 to a3ffffff) ? pdc0 access to: ? sram0, rom ? ebi (through 0x60000000 to 0x63ffffff) ? hbridge0 ? icm access to: ? flash, rom, sram0, sram1 through matrix1, sram2 through matrix1 ? pkcc ? ebi through 0x60000000 to 0x63ffffff) ? hbridge1 through matrix1 ? matrix1 access to ? flash through 0x01000000 to 0x01ffffff and 0x11000000 to 0x11ffffff) ? sram0 ? hbridge0 ? ebi matrix1 access to: ? ebi through 0x03000000 to 0x06ffffff, 0x13000000 to 0x16ffffff, ? 0x60000000 to 0x63ffffff, 0xa0000000 to 0xa3ffffff) ? cache controller cmcc0 access to: ? flash (through 0x11000000 to 0x11ffffff) table 26-3. matrix 0 m aster to slave access slaves masters 0 1 2 3 4 5 6 reserved cortex-m4 i/d bus cortex-m4 s bus pdc0 icm matrix1 ebi matrix 1 cmcc0 0 internal sram0 - x x x x - - - 1 internal rom x - x x - - - - 2 internal flash x - - x x - x - 3 external bus interface x x x x - x x - 4 peripheral bridge 0 - x x - x - - - 5 cpkcc sram, rom - x - x - - - - 6matrix1 -x-x---- 7 cmcc0 x - - - - - - -
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 478 ? ebi (through 0x13000000 to 0x16ffffff) 26.2.2 matrix 1 26.2.2.1 matrix 1 masters the bus matrix 1, which corresponds to the sub-system 1 (core 1 - cm4p1), manages the masters listed in table 26-4 . each master can perform an access to an available slave concurrently with other masters. each master has its own specifically-def ined decoder. in order to simplify the addressing, all the masters have the same decodings. 26.2.2.2 matrix 1 slaves the bus matrix manages the slaves listed in table 26-2 . each slave has its own arbiter providing a dedicated arbitration per slave. table 26-4. list of bus matrix masters master 0 cortex-m4 instruct ion/data (cm4p1 i/d bus) master 1 cortex-m4 system (cm4p1 s bus) master 2 peripheral dma controller 1 (pdc1) master 3 matrix0 master 4 ebi matrix0 master 5 cmcc1 table 26-5. list of bus matrix slaves slave 0 internal sram1 slave 1 internal sram2 slave 2 external bus interface slave 3 peripheral bridge 1 slave 4 matrix0 slave 5 cmcc1
479 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 26.2.2.3 master to slave access (matrix 1) table 26-6 gives valid paths for master to slave access on ma trix 1. the paths shown as ?-? are forbidden or not wired, e.g. access from the cortex -m4 s bus to the internal rom. 26.2.2.4 accesses through matrix 1 ? cm4p1 i/d bus access to: ? flash (through 0x01000000 to 0x01ffffff) ? ebi (through 0x03000000 to 0x06ffffff) ? flash and ebi through cache cmcc1 ? cm4p1 s-bus access to: ? sram1, sram2, sram0 through matrix0 (0x20000000), ? ebi (0x60000000 to 0x63ffffff and 0xa0000000 to 0xa3ffffff), ? hbridge1, hbridge0 thro ugh matrix0 (0x40000000) ? pdc1 access to: ? sram1, sram2 ? ebi (0x60000000 to 0x63ffffff), ? hbridge1 ? matrix0 access to: ? sram1, sram2, ? hbridge1 ? ebi from matrix 0 access to: ? ebi (through 0x030000000 to 0x06fffffff, 0x60000000 to 0x63ffffff, 0xa0000000 to a3ffffff) ? cache cmcc1 access to: ? flash through 0x11000000, ? ebi through 0x13000000 to 0x16ffffff table 26-6. matrix 1 m aster to slave access slaves masters 0 1 2 3 4 5 cortex-m4 i/d bus cortex-m4 s bus pdc1 matrix0 ebi matrix 0 cmcc1 0 internal sram1 x x x x - - 1 internal sram2 - x x x - - 2 external bus interface x x x - x x 3 peripheral bridge 1 - x x x - - 4m a t r i x 0 xx---x 5c m c c 1 x-----
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 480 26.3 special bus granting mechanism the bus matrix provides some speculative bus granting te chniques in order to anticipate access requests from masters. this mechanism reduces latency at first access of a burst, or for a si ngle transfer, as long as the slave is free from any other master access. however, the technique does not provide any benefits if the slave is continuously accessed by more than one master, since arbi tration is pipelined and has no negative effect on the slave bandwidth or access latency. this bus granting mechanism sets a di fferent default master for every slave. at the end of the current access, if no other request is pending, the slave remains connected to its associated default master. a slave can be associat ed with three kinds of default masters: ? no default master ? last access master ? fixed default master to change from one type of default mast er to another, the bus matrix user interface provides slave configuration registers, one for every slave which set a default master for each slave. the slave configuration register contains two fields to manage master selection: defmstr_ type and fixed_defmstr. the 2-bit defmstr_type field selects the default master type (no default, last access master, fixe d default master), whereas the 4-bit fixed_defmstr field selects a fixed default master pr ovided that defmstr_type is set to fixed default master. refer to section 26.9.2 ?bus matrix slave configuration registers? on page 487 . 26.4 no default master after the end of the current access, if no other request is pending, the slave is disconnected from all masters. this configuration incurs one latency clock cycle for the first access of a burst after bus idle. arbitration without the default master may be used for masters that perform signifi cant bursts or several tran sfers with no idle in between, or if the slave bus bandwidth is wi dely used by one or more masters. this configuration provides no bene fit on access latency or bandwidth when reaching maximum slave bus throughput regardless of the number of requesting masters. 26.5 last access master after the end of the current access, if no other request is pending, the slav e remains connected to the last master that performed an access request. this allows the bus matrix to remove one latency cycle for the last master that accessed the slave. other non- privileged masters still get one latency cl ock cycle if they need to access the sa me slave. this technique is used for masters that perform single accesses or short bursts with some idle cycles in between. this configuration provides no bene fit on access latency or bandwidth when reaching maximum slave bus throughput whatever is the number of requesting masters. 26.6 fixed default master after the end of the current access, if no other request is pending, the slave connects to its fixed default master. unlike the last access master, the fixed default master does not change unless the user modifies it by software (fixed_defmstr field of the related matrix_scfg). this allows the bus matrix arbiters to remove the one la tency clock cycle for the fixed default master of the slave. all requests attempted by the fixed default master do not cause any arbitration latency, whereas other non- privileged masters will get one latency cy cle. this technique is used for a master that mainly performs single accesses or short bursts with idle cycles in between.
481 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 this configuration provides no bene fit on access latency or bandwidth when reaching maximum slave bus throughput, regardless of the number of requesting masters. 26.7 arbitration the bus matrix provides an arbitration mechanism that reduces latency when a conflict occurs, i.e. when two or more masters try to access the same slave at the sa me time. one arbiter per ahb slave is provided, thus arbitrating each slave specifically. the bus matrix provides the user with the possibility of choosing between tw o arbitration types or mixing them for each slave: 1. round-robin arbitration (default) 2. fixed priority arbitration the resulting algorithm may be complemented by select ing a default master conf iguration for each slave. when re-arbitration must be done, specific conditions apply. see section 26.7.1 ?arbitration scheduling? on page 481 . 26.7.1 arbitration scheduling each arbiter has the ability to arbitrate between two or more master requests. in order to avoid burst breaking and also to provide the maximum throughput for slave interfac es, arbitration may only take place during the following cycles: 1. idle cycles: when a slave is not connected to any ma ster or is connected to a master which is not cur- rently accessing it 2. single cycles: when a slave is currently doing a single access 3. end of burst cycles: when the current cycle is the la st cycle of a burst transfer. for defined burst length, predicted end of burst matches the size of the transfer but is managed di fferently for undefined burst length. see ?undefined length burst arbitration? on page 481 4. slot cycle limit: when the slot cycle counter has reached the lim it value, indicating th at the current master access is too long and must be broken. see ?slot cycle limit arbitration? on page 482 26.7.1.1 undefined length burst arbitration in order to prevent long ahb burst lengths that can lock the access to the slave for an excessive period of time, the user can trigger the re-arbitration before the end of the incremental bursts. the re-arbitration period can be selected from the following undefined length burst type (ulbt) possibilities: 1. unlimited: no predetermined end of burst is generated. this value enables 1-kbyte burst lengths. 2. 1-beat bursts: predetermin ed end of burst is generat ed at each single transfer during the incr transfer. 3. 4-beat bursts: predetermined end of burst is generated at the end of each 4-beat boundary during incr transfer. 4. 8-beat bursts: predetermined end of burst is generated at the end of each 8-beat boundary during incr transfer. 5. 16-beat bursts: predetermined end of burst is generat ed at the end of each 16-beat boundary during incr transfer. 6. 32-beat bursts: predetermined end of burst is generat ed at the end of each 32-beat boundary during incr transfer. 7. 64-beat bursts: predetermined end of burst is generat ed at the end of each 64-beat boundary during incr transfer. 8. 128-beat bursts: predetermined end of burst is generated at the end of each 128 -beat boundary during incr transfer.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 482 the use of undefined length 8-beat bursts or less is discouraged since this may decrease the overall bus bandwidth due to arbitration and slave la tencies at each first access of a burst. however, if the usual length of undefined length bursts is known for a master, it is recommended to configure the ulbt according to this length. this selection can be done through the ulbt field of the master configuration registers (matrix_mcfg). 26.7.1.2 slot cycle limit arbitration the bus matrix contains specific logic to break long accesse s, such as very long bursts on a very slow slave (e.g., an external low speed memory). at each arbitration time, a counter is loaded with the value previously written in the slot_cycle field of the related slave configuratio n register (matrix_scfg) an d decreased at each clock cycle. when the counter elapses, the ar biter has the ability to re-arbitrate at the end of the current ahb bus access cycle. unless a master has a very tight access latency constraint, which could lead to data overflow or underflow due to a badly undersized internal fifo with respect to its throughput, the slot cycle limit should be disabled (slot_cycle = 0) or set to its default maximum value in order not to inefficiently break long bursts performed by some atmel masters. in most cases, this feature is not neede d and should be disabled for power saving. warning: this feature cannot prevent any slave from locking its access indefinitely. 26.7.2 arbitration priority scheme the bus matrix arbitration scheme is organized in priori ty pools. the corresponding access criticality class is assigned to each priority pool as shown in the ?latency quality of service? column in table 26-7 . latency quality of service is determined through the bus matrix user interface. see section 26.9.3 ?bus matr ix priority registers a for slaves? for details. round-robin priority is used in the highest and lowest prio rity pools 3 and 0, whereas fi xed level priority is used between priority pools and in the intermediate priority pools 2 and 1. see section 26.7.2.2 ?round-robin arbitration? . for each slave, each master is assigned to one of the sl ave priority pools through the latency quality of service inputs or through the priority registers for slaves (mxpr fields of matrix_pras and matrix_prbs). when evaluating master requests, this priority pool level always takes precedence. after reset, most of the masters belong to the lowest pr iority pool (mxpr = 0, background transfer) and, therefore, are granted bus access in a true round-robin order. the highest priority pool must be spec ifically reserved for masters requiring very low access la tency. if more than one master belongs to this pool, they will be granted bus access in a biased round-robin manner which allows tight and deterministic maximum access lat ency from ahb bus requests. in the worst case, any currently occurring high-priority master request will be granted after the current bus mast er access has ended a nd other high priority pool master requests, if any, have been granted once each. the lowest priority pool shares the re maining bus bandwidth between ahb masters. table 26-7. arbitrati on priority pools priority pool latency quality of service 3 latency critical 2 latency sensitive 1 bandwidth sensitive 0 background transfers
483 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 intermediate priority pools allow fine priority tuning. ty pically, a latency-sensitive ma ster or a bandwidth-sensitive master will use such a priority level. the higher the priority level (mxpr va lue), the higher the master priority. to ensure a good level of cpu performance, it is recomm ended to configure the cpu priority with the default reset value 2 (latency sensitive). all combinations of mxpr values are allowed for all masters and slaves. for example, some masters might be assigned the highest priority pool (round-robin), and rema ining masters the lowest prio rity pool (round-robin), with no master for intermediate fix priority levels. 26.7.2.1 fixed priority arbitration fixed priority arbitration algorithm is the first and only arbitr ation algorithm applied between masters from distinct priority pools. it is also used in priori ty pools other than the highest and lowe st priority pools (i ntermediate priority pools). fixed priority arbitration allows the bus matrix arbiters to dispatch the requests from different masters to the same slave by using the fixed priority defined by the user in the mxpr field for each master in the priority registers, matrix_pras and matrix_prbs. if two or more master re quests are active at the same time, the master with the highest priority mxpr number is serviced first. in intermediate priority pools, if two or more master requests with the same priority are active at the same time, the master with the highest number is serviced first. 26.7.2.2 round-robin arbitration this algorithm is only used in the highest and lowest priority pools. it allows the bus matrix arbiters to properly dispatch requests from different masters to the same slave. if two or more master requests are active at the same time in the priority pool, they are serviced in a round-robin increasing master number order. 26.8 register write protection to prevent any single software error from corrupting the bus matrix behavior, certain registers in the address space can be write-protected by setting the wpen bit in the ?write protection mode register? (matrix_wpmr). if a write access to a writ e-protected register is dete cted, the wpvs flag in the ?write protection status register? (matrix_wpsr) is set and the field wpvsrc indicates the register in which th e write access has been attempted. the wpvs bit is automatically cleared after reading the matrix_wpsr. the following registers can be write-protected: ? ?bus matrix master configuration registers? ? ?bus matrix slave configuration registers? ? ?bus matrix priority registers a for slaves? ? ?system i/o configuration register?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 484 26.9 ahb bus matrix (mat rix) user interface table 26-8. register mapping offset register name access reset 0x0000 master configuration register 0 matrix_mcfg0 read/write 0x00000004 0x0004 master configuration register 1 matrix_mcfg1 read/write 0x00000004 0x0008 master configuration register 2 matrix_mcfg2 read/write 0x00000004 0x000c master configuration register 3 matrix_mcfg3 read/write 0x00000004 0x0010 master configuration register 4 matrix_mcfg4 read/write 0x00000004 0x0014 master configuration register 5 matrix_mcfg5 read/write 0x00000004 0x0018 master configuration register 6 matrix_mcfg6 read/write 0x00000004 0x001c - 0x003c reserved ? ? ? 0x0040 slave configuration register 0 matrix_scfg0 read/write 0x000001ff 0x0044 slave configuration register 1 matrix_scfg1 read/write 0x000001ff 0x0048 slave configuration register 2 matrix_scfg2 read/write 0x000001ff 0x004c slave configuration register 3 matrix_scfg3 read/write 0x000001ff 0x0050 slave configuration register 4 matrix_scfg4 read/write 0x000001ff 0x0054 slave configuration register 5 matrix_scfg5 read/write 0x000001ff 0x0058 slave configuration register 6 matrix_scfg6 read/write 0x000001ff 0x005c slave configuration register 7 matrix_scfg7 read/write 0x000001ff 0x005c - 0x007c reserved ? ? ? 0x0080 priority register a for slave 0 matrix_pras0 read/write 0x00000000 (1) 0x0084 reserved ? ? ? 0x0088 priority register a for slave 1 matrix_pras1 read/write 0x00000000 (1) 0x008c reserved ? ? ? 0x0090 priority register a for slave 2 matrix_pras2 read/write 0x00000000 (1) 0x0094 reserved ? ? ? 0x0098 priority register a for slave 3 matrix_pras3 read/write 0x00000000 (1) 0x009c reserved ? ? ? 0x00a0 priority register a for slave 4 matrix_pras4 read/write 0x00000000 (1) 0x00a4 reserved ? ? ? 0x00a8 priority register a for slave 5 matrix_pras5 read/write 0x00000000 (1) 0x00ac reserved ? ? ? 0x00b0 priority register a for slave 6 matrix_pras6 read/write 0x00000000 (1) 0x00b4 reserved ? ? ? 0x00b8 priority register a for slave 7 matrix_pras7 read/write 0x00000000 (1) 0x00bc - 0x0110 reserved ? ? ? 0x0114 system i/o configuration register matrix_sysio read/write 0x00000000 0x0118 reserved ? ? ?
485 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 note: 1. values in the bus matrix priority registers are product dependent. 0x011c smc nand flash chip select configuration register matrix_smcnfcs read/write 0x00000000 0x0120 reserved ? ? ? 0x0124 reserved ? ? ? 0x0128 core debug configuration register matrix_core_debug read/write 0x00000000 0x012c - 0x01e0 reserved ? ? ? 0x01e4 write protection mode register matrix_wpmr read/write 0x00000000 0x01e8 write protection status r egister matrix_wpsr read-only 0x00000000 table 26-8. register mapping (continued) offset register name access reset
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 486 26.9.1 bus matrix master configuration registers name: matrix_mcfgx [x=0..6] address: 0x400e0200 (0), 0x48010000 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?write protection mode register? . ? ulbt: undefined length burst type 0: unlimited length burst no predicted end of burst is generated, therefore incr bursts co ming from this master can only be broken if the slave slot cycle limit is reached. if the slot cycle li mit is not reached, the burst is normally completed by the master, at the latest, o n the next ahb 1 kbyte address boundary, allowing up to 256-beat word bursts or 128-beat double-word bursts. this value should not be used in the specific case of a master capable of performing back-to-back undefined length bursts on a single slave. this could cause an indefinite freeze of the slave arbitration and thus prevent another master from accessing this slave. 1: single access the undefined length burst is treated as a succession of single accesses, allowing re-arbitration at each beat of the incr burst or bursts sequence. 2: 4-beat burst the undefined length burst or bursts sequence is split into 4-beat bursts or less, allowing re-arbitration every 4 beats. 3: 8-beat burst the undefined length burst or bursts sequence is split into 8-beat bursts or less, allowing re-arbitration every 8 beats. 4: 16-beat burst the undefined length burst or bursts sequence is split into 16-beat bursts or less, allowing re-arbitration every 16 beats. 5: 32-beat burst the undefined length burst or bursts sequence is split into 32-beat bursts or less, allowing re-arbitration every 32 beats. 6: 64-beat burst the undefined length burst or bursts sequence is split into 64-beat bursts or less, allowing re-arbitration every 64 beats. 7: 128-beat burst the undefined length burst or bursts sequence is split into 12 8-beat bursts or less, allowing re-arbitration every 128 beats. unless duly needed, the ulbt should be left at its default 0 value for power saving. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????? u l b t
487 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 26.9.2 bus matrix slave configuration registers name: matrix_scfgx [x=0..7] address: 0x400e0240 (0), 0x48010040 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?write protection mode register? . ? slot_cycle: maximum bus gr ant duration for masters when slot_cycle ahb clock cycles have elapsed since the last arbitration, a new arbitration takes place to let another master access this slave. if another master is requesting the slave bus, th en the current master burst is broken. if slot_cycle = 0, the slot cycle limit feature is disabled and bursts always complete unless broken according to the ulbt. this limit has been placed in order to enforce arbitration so as to meet potential latency cons traints of masters waiting for slave access. this limit must not be too sm all. unreasonably small values break every bur st and the bus matrix arbitrates without per- forming any data transfer. the default maximum va lue is usually an optimal conservative choice. in most cases, this feature is not neede d and should be disabled for power saving. see section 26.7.1.2 ?slot cycle limit arbitration? for details. ? defmstr_type: default master type 0: no default master at the end of the current slave access, if no other master request is pending, the slave is disconnected from all masters. this results in a one clock cycle latency for the firs t access of a burst transfer or for a single access. 1: last default master at the end of the current slave access, if no other master reque st is pending, the slave stays connected to the last master having accessed it. this results in not having one clock cycle latency when the last master tries to access the slave again. 2: fixed default master at the end of the current slave access, if no other master re quest is pending, the slave conn ects to the fixed master the number that has been written in the fixed_defmstr field. this results in not having one clock cycle latency wh en the fixed master tries to access the slave again. ? fixed_defmstr: fixed default master this is the number of the default master for this slave. only used if defmstr_type is 2. specifying the number of a master which is not conn ected to the selected sl ave is equivalent to se tting defmstr_type to 0. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? fixed_defmstr defmstr_type 15 14 13 12 11 10 9 8 ???????s l o t _ c y c l e 76543210 slot_cycle
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 488 26.9.3 bus matrix priority registers a for slaves name: matrix_prasx [x=0..7] address: 0x400e0280 (0)[0], 0x400e0288 (0)[1], 0x400e02 90 (0)[2], 0x400e0298 (0)[3], 0x400e02a0 (0)[4], 0x400e02a8 (0)[5], 0x400e02b0 (0)[6], 0x400e02b8 (0)[7] 0x48010080 (1)[0], 0x48010088 (1)[1], 0x48010090 (1)[2], 0x48010098 (1)[3], 0x480100a0 (1)[4], 0x480100a8 (1)[5], 0x480100b0 (1)[6], 0x480100b8 (1)[7] access: read/write this register can only be written if the wpe bit is cleared in the ?write protection mode register? . ? mxpr: master x priority fixed priority of master x for accessi ng the selected slave. the higher the number, the higher the priority. all the masters programmed with the same mxpr value for the slave make up a priority pool. round-robin arbitration is used in the lowest (m xpr = 0) and highest (mxpr = 3) priority pools. fixed priority is used in intermediate priority pools (mxpr = 1) and (mxpr = 2). see ?arbitration priority scheme? on page 482 for details. 31 30 29 28 27 26 25 24 ?m 7 p r ?m 6 p r 23 22 21 20 19 18 17 16 ?m 5 p r ?m 4 p r 15 14 13 12 11 10 9 8 ?m 3 p r ?m 2 p r 76543210 ?m 1 p r ?m 0 p r
489 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 26.9.4 system i/o configuration register name: matrix_sysio address: 0x400e0314 (0), 0x48010114 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?write protection mode register? . ? sysio0: pb0 or tdi assignment 0: tdi function selected. 1: pb0 function selected. ? sysio1: pb1 or tdo/traceswo assignment 0: tdo/traceswo function selected. 1: pb1 function selected. ? sysio2: pb2 or tms/swdio assignment 0: tms/swdio function selected. 1: pb2 function selected. ? sysio3: pb3 or tck/swclk assignment 0: tck/swclk function selected. 1: pb3 function selected. ? sysio9: pc9 or erase assignment 0: erase function selected. 1: pc9 function selected. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?????? sysio9 76543210 ???? sysio3 sysio2 sysio1 sysio0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 490 26.9.5 smc nand flash chip select configuration register name: matrix_smcnfcs address: 0x400e031c (0), 0x4801011c (1) access: read/write ? smc_nfcs0: smc nand flash chip select 0 assignment 0: ncs0 is not assigned to a nand fl ash (nandoe and nanwe not used for ncs0) 1: ncs0 is assigned to a nand flash (nandoe and nanwe used for ncs0) ? smc_nfcs1: smc nand flash chip select 1 assignment 0: ncs1 is not assigned to a nand fl ash (nandoe and nanwe not used for ncs1) 1: ncs1 is assigned to a nand flash (nandoe and nanwe used for ncs1) ? smc_nfcs2: smc nand flash chip select 2 assignment 0: ncs2 is not assigned to a nand fl ash (nandoe and nanwe not used for ncs2) 1: ncs2 is assigned to a nand flash (nandoe and nanwe used for ncs2) ? smc_nfcs3: smc nand flash chip select 3 assignment 0: ncs3 is not assigned to a nand fl ash (nandoe and nanwe not used for ncs3) 1: ncs3 is assigned to a nand flash (nandoe and nanwe used for ncs3) ? smc_sel: smc selection for ebi pins 0: ebi pins are used by smc0 1: ebi pins are used by smc1 31 30 29 28 27 26 25 24 s m c _ s e l??????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????s m c _ n f c s 3 s m c _ n f c s 2 s m c _ n f c s 1 s m c _ n f c s 0
491 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 26.9.6 core debug configuration register name: matrix_core_debug address: 0x400e0328 (0), 0x48010128 (1) access: read/write ? cross_trig1: core 1 --> core 0 cross triggering 0: core 1 is not able to trigger an event on core 0. 1: core 1 is able to trigger an event on core 0. ? cross_trig0: core 0 --> core 1 cross triggering 0: core 0 is not able to trigger an event on core 1. 1: core 0 is able to trigger an event on core 1. 31 30 29 28 27 26 25 24 ?? ? ? ? ? ? ? 23 22 21 20 19 18 17 16 ?? ? ? ? ? ? ? 15 14 13 12 11 10 9 8 ?? ? ? ? ? ? ? 76 5 4 3 2 1 0 ? ? ? ? ? cross_trg0 cross_trg1 ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 492 26.9.7 write protection mode register name: matrix_wpmr address: 0x400e03e4 (0), 0x480101e4 (1) access: read/write for more information on write pr otection registers, refer to section 26.8 ?register write protection? . ? wpen: write protect enable 0: disables the write protection if wpkey corresponds to 0x4d4154 (?mat? in ascii). 1: enables the write protecti on if wpkey corres ponds to 0x4d4154 (?mat? in ascii). see section 26.8 ?register write protection? for the list of registers that can be protected. ? wpkey: write protect key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x4d4154 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
493 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 26.9.8 write protection status register name: matrix_wpsr address: 0x400e03e8 (0), 0x480101e8 (1) access: read-only for more information on write pr otection registers, refer to section 26.8 ?register write protection? . ? wpvs: write protection violation status 0: no write protection violation has occurred si nce the last read of th e matrix_wpsr register. 1: a write protection violation has occurred since the last read of the matrix_wpsr register. if this violation is an unau- thorized attempt to write a protected regi ster, the associated violation is report ed into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at whic h a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 494 27. static memory controller (smc) 27.1 description the external bus interface is designed to ensure the succ essful data transfer between several external devices and the cortex-m4-based device . the external bus interface of the sam4c consists of a static memory controller (smc). this smc is capable of handling several types of exte rnal memory and peripheral devices, such as sram, psram, prom, eprom, eeprom, lcd module, nor flash and nand flash. the static memory controller (smc) generates the signals that control the access to the external memory devices or peripheral devices. it has 4 chip selects, a 24-bit address bus, and a configurable 8 or 16-bit data bus. separate read and write control sign als allow for direct memory and perip heral interfacing. read and write signal waveforms are fully adjustable. the smc can manage wait requests from external devices to extend the current access. the smc is provided with an automatic slow clock mode. in slow clock mode, it switches from user-programmed waveforms to slow-rate specific waveforms on read and write signals. the smc supports asynchronous burst read in page mode access for page sizes up to 32 bytes. the external data bus can be scrambled/unscrambled by means of user keys. 27.2 embedded characteristics ? 4 chip selects available ? 16-mbyte address space per chip select ? 8-bit or 16-bit data bus ? zero wait state scrambling/unscrambling function with user key ? word, halfword, byte transfers ? byte write or byte select lines ? programmable setup, pulse and hold time for read signals per chip select ? programmable setup, pulse and hold time for write signals per chip select ? programmable data float time per chip select ? external data bus scramb ling/unscrambling function ? external wait request ? automatic switch to slow clock mode ? asynchronous read in page mode supported: page size ranges from 4 to 32 bytes ? write protected registers
495 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.3 i/o lines description 27.4 product dependencies 27.4.1 i/o lines the pins used for interfacing the static memory cont roller are multiplexed with th e pio lines. the programmer must first program the pio controller to assign the static memory controller pins to th eir peripheral function. if i/o lines of the smc are not used by the application, they can be used for other purposes by the pio controller. 27.4.2 power management the smc is clocked through the power management contro ller (pmc), thus the progra mmer must first configure the pmc to enable the smc clock. 27.5 multiplexed signals table 27-1. i/o line description name description type active level ncs[3:0] static memory controller chip select lines output low nrd read signal output low nwr0/nwe write 0/write enable signal output low nwr1/nbs1 write 1/byte 1 select signal output low a0/nbs0 address bit 0/byte 0 select signal output low a[23:1] address bus output ? d[15:0] data bus i/o ? nwait external wait signal input low nandcs nand flash chip select line output low nandoe nand flash output enable output low nandwe nand flash write enable output low nandale nand flash address latch enable output ? nandcle nand flash command latch enable output ? table 27-2. static memory contro ller (smc) multiplexed signals multiplexed signals related function nwr0 nwe byte-write or byte-select access. see section 27.7.2.1 ?b yte write access? and section 27.7.2.2 ?b yte select access? a0 nbs0 8-bit or 16-bit data bus. see section 27.7.1 ?d ata bus width? nwr1 nbs1 byte-write or byte -select access. see section 27.7.2.1 ?byte write access? and section 27.7.2.2 ?byte select access? a22 nandcle nand flash command latch enable a21 nandale nand flash address latch enable
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 496 27.6 external memory mapping the smc provides up to 24 address lines , a[23:0]. this allows each chip select line to address up to 16 mbytes of memory. if the physical memory device connecte d on one chip select is smaller than 16 mbytes, it wraps around and appears to be repeated within this space. the smc correctly handles any valid access to the memory device within the page (see figure 27-1 ). figure 27-1. memory connections for four external devices nrd nwe a[23:0] d[15:0] 16 or 8 memory enable memory enable memory enable memory enable output enable write enable a[23:0] d[15:0] or d[7:0] ncs3 ncs0 ncs1 ncs2 ncs[0] - ncs[3] smc 24
497 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.7 connection to external devices 27.7.1 data bus width a data bus width of 8 or 16 bits can be selected for each ch ip select. this option is controlled by the bit dbw in the smc mode register (smc_mode) for the corresponding chip select. figure 27-2 shows how to connect a 512-kbyte x 8-bit memory on ncs2. figure 27-3 shows how to connect a 512-kbyte x 16-bit memory on ncs2. figure 27-2. memory connection for an 8-bit data bus figure 27-3. memory connection for a 16-bit data bus 27.7.2 byte write or byte select access each chip select with a 16-bit data bus can operate with one of two different types of write access: byte write or byte select. this is controlled by the bat bit of the smc_mode register for the corresponding chip select. 27.7.2.1 byte write access byte write access is used to connect 2 x 8-bit devices as a 16-bit memory, and supports one write signal per byte of the data bus and a single read signal. note that the smc does not allow boot in byte write access mode. for 16-bit devices, the smc provides nw r0 and nwr1 write signals for respec tively byte0 (lower byte) and byte1 (upper byte) of a 16-bit bus. one single read signal (nrd) is provided. 27.7.2.2 byte select access byte select access is used to connect one 16-bit device. in this mode, read /write operations can be enabled/disabled at byte level. one byte-select line per byte of the data bus is provided. one nrd and one nwe signal control read and write. smc a1 nwe nrd ncs[2] a1 write enable output enable memory enable d[7:0] d[7:0] a[18:2] a[18:2] a0 a0 smc nbs0 nwe nrd ncs[2] low byte enable write enable output enable memory enable nbs1 high byte enable d[15:0] d[15:0] a[19:2] a[18:1] a[0] a1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 498 for 16-bit devices, the smc provides nbs0 and nbs1 se lection signals for respectively byte0 (lower byte) and byte1 (upper byte) of a 16-bit bus. figure 27-4. connection of 2 x 8-bit devices on a 16-bit bus: byte write option 27.7.2.3 signal multiplexing depending on the byte access type (bat ), only the write signals or the byte select signals are used. to save ios at the external bus interfac e, control signals at the smc interface are multiplexed. table 27-3 shows signal multiplexing depending on the data bus width and the byte access type. for 16-bit devices, bit a0 of address is unused. when by te select option is selected, nwr1 is unused. when byte write option is selected, nbs0 is unused. smc a1 nwr0 nrd ncs[3] write enable read enable memory enable nwr1 write enable read enable memory enable d[7:0] d[7:0] d[15:8] d[15:8] a[24:2] a[23:1] a[23:1] a[0] a[0] table 27-3. smc multiplexed signal translation device type signal name 16-bit bus 8-bit bus 1 x 16-bit 2 x 8-bit 1 x 8-bit byte access type (bat) byte select byte write ? nbs0_a0 nbs0 ? a0 nwe_nwr0 nwe nwr0 nwe nbs1_nwr1 nbs1 nwr1 ? a1 a1 a1 a1
499 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.7.3 nand flash support the smc integrates circuitry that interfaces to nand flash devices. the nand flash logic is driven by the static memo ry controller. it depends on the programming of the smc_nfcsx field in the ccfg_smcnfcs regi ster on the bus matrix user interface. for details on this register, refer to the bus matrix user interface section. access to an external nand flash device via the address space reserved to the chip select programmed. the user can connect up to 4 nand flash devices with separate chip select. the nand flash logic drives the read and write command signals of the smc on the nandoe and nandwe signals when the ncsx programmed is active. nandoe and nandwe are disabled as soon as the transfer address fails to lie in the ncsx programmed address space. figure 27-5. nand flash signal multiplexing on smc pins note: when the nand flash logic is activated, (smcnfcsx=1) , the nwe pin cannot be used in pio mode but only in peripheral mode (nwe function). if the nwe function is not used for other external memories (sram, lcd), it must be configured in one of the following modes. ? pio input with pull-up enabled (default state after reset) ? pio output set at level 1 the address latch enable and command latch enable signal s on the nand flash device are driven by address bits a22 and a21of the address bus. any bit of the addres s bus can also be used for this purpose. the command, address or data words on the data bus of the nand flash device use their own addresses within the ncsx address space (configured by ccfg_smcnfcs register on the bus matrix user interface). the chip enable (ce) signal of the device and t he ready/busy (r/b) signals are connected to pio lines. the ce signal then remains asserted even when ncs3 is not selected, preventing the device from returning to standby mode. the nandcs output signal should be used in accordance with the external nand flash device type. two types of ce behavior exist depending on the nand flash device: ? standard nand flash devices require that the ce pin remains asserted low continuously during the read busy period to prevent the device from returning to standby mode. si nce the static memory controller (smc) asserts the ncsx signal high, it is necessary to connect the ce pin of the nand flash device to a gpio line, in order to hold it low during the busy period preceding data read out. ? this restriction has been removed for ?ce don?t care? nand flash devices. the ncsx signal can be directly connected to the ce pin of the nand flash device. figure 27-6 illustrates both topolog ies: standard and ?ce don?t care? nand flash. smc nrd nwe nandoe nandwe nand flash logic ncsx (activated if smc_nfcsx=1) * nandwe nandoe * in ccfg_smcnfcs matrix register
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 500 figure 27-6. standard and ?ce don?t care? nand flash application examples 27.8 application example 27.8.1 implementation examples hardware configurations are given for illu stration only. the user s hould refer to th e manufacturer web site to check for memory device availability. for hardware implementation examples, refer to sam4c- ek schematics, which show examples of a connection to an lcd module and nand flash. d[7:0] ale nandwe noe nwe a[22:21] cle ad[7:0] pio r/b smc ce nand flash pio ncsx not connected nandoe d[7:0] ale nandwe noe nwe a[22:21] cle ad[7:0] pio r/b smc ce ?ce don?t care? nand flash ncsx nandoe
501 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.8.1.1 8-bit nand flash 27.8.1.2 hardware configuration 27.8.1.3 software configuration perform the following configuration: ? assign the smc_nfcsx (for example smc_nfcs3) field in the ccfg_smcnfcs register on the bus matrix user interface. ? reserve a21 / a22 for ale / cle fu nctions. address and command latche s are controlled respectively by setting to 1 the address bits a21 and a22 during accesses. ? nandoe and nandwe signals are multiplexed with pio lines. thus, the dedicated pios must be programmed in peripheral mode in the pio controller. ? configure a pio line as an input to manage the ready/busy signal. ? configure static memory controller cs3 setup, pulse, cycle and mode according to nand flash timings, the data bus width and the system bus frequency. in this example, the nand flash is not addressed as a ?ce don?t care?. to add ress it as a ?ce don?t care?, connect ncs3 (if smc_nfcs3 is set) to the nand flash ce. d6 d0 d3 d4 d2 d1 d5 d7 nandoe nandwe (any pio) (any pio) ale cle d[0..7] 3v3 3v3 2 gb tsop48 package u1 k9f2g08u0m u1 k9f2g08u0m we 18 n.c 6 vcc 37 ce 9 re 8 n.c 20 wp 19 n.c 5 n.c 1 n.c 2 n.c 3 n.c 4 n.c 21 n.c 22 n.c 23 n.c 24 r/b 7 n.c 26 n.c 27 n.c 28 i/o0 29 n.c 34 n.c 35 vss 36 pre 38 n.c 39 vcc 12 vss 13 ale 17 n.c 11 n.c 10 n.c 14 n.c 15 cle 16 n.c 25 n.c 33 i/o1 30 i/o3 32 i/o2 31 n.c 47 n.c 46 n.c 45 i/o7 44 i/o6 43 i/o5 42 i/o4 41 n.c 40 n.c 48 r2 10k r2 10k c2 100nf c2 100nf r1 10k r1 10k c1 100nf c1 100nf
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 502 27.8.1.4 nor flash 27.8.1.5 hardware configuration 27.8.1.6 software configuration configure the static memory controller cs0 setu p, pulse, cycle and mode depending on flash timings and system bus frequency. 27.9 standard read and write protocols in the following sections, the byte access type is not considered. byte select lines (nbs0 to nbs1) always have the same timing as the a address bus. nwe represents eith er the nwe signal in byte select access type or one of the byte write lines (nwr0 to nwr1) in byte write access type. nwr0 to nwr1 have the same timings and protocol as nwe. if d[15:8] are used, they have the same timing as d[7:0]. in the same way, ncs represents one of the ncs[0..3] chip select lines. 27.9.1 read waveforms the read cycle is shown on figure 27-7 . the read cycle starts with the address setting on the memory address bus. a21 a1 a0 a2 a3 a4 a5 a6 a7 a8 a15 a9 a12 a13 a11 a10 a14 a16 d6 d0 d3 d4 d2 d1 d5 d7 a17 a20 a18 a19 d[0..7] a[0..21] nrst nwe ncs0 nrd 3v3 3v3 c2 100nf c2 100nf c1 100nf c1 100nf u1 u1 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a21 a20 a19 we reset wp oe ce vpp dq0 dq1 dq2 dq3 dq4 dq5 dq6 dq7 vccq vss vss vcc
503 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-7. standard read cycle 27.9.1.1 nrd waveform the nrd signal is characterized by a setu p timing, a pulse width and a hold timing. 1. nrd_setup: the nrd setup time is defined as the setup of addr ess before the nrd falling edge; 2. nrd_pulse: the nrd pulse length is the time between nrd falling edge and nrd rising edge; 3. nrd_hold: the nrd hold time is defined as the hold time of address after the nrd rising edge. 27.9.1.2 ncs waveform similarly, the ncs signal can be divided into a setup time, pulse length and hold time: 1. ncs_rd_setup: the ncs setup time is defined as the setup time of address before the ncs falling edge. 2. ncs_rd_pulse: the ncs pulse le ngth is the time between ncs fa lling edge and ncs rising edge; 3. ncs_rd_hold: the ncs hold time is defined as th e hold time of address after the ncs rising edge. 27.9.1.3 read cycle the nrd_cycle time is defined as the to tal duration of the read cycle, i.e., from the time where address is set on the address bus to the point where address may change. the total read cycle time is equal to: nrd_cycle = nrd_setup + nrd_pulse + nrd_hold = ncs_rd_setup + ncs_rd_pulse + ncs_rd_hold all nrd and ncs timings are defined separately for each ch ip select as an integer number of master clock cycles. to ensure that the nrd and ncs timings are coherent, user must define the total read cycle instead of the hold timing. nrd_cycle implicitly defines t he nrd hold time and ncs hold time as: nrd_hold = nrd_cycle - nrd setup - nrd pulse ncs_rd_hold = nrd_cycle - ncs_rd_setup - ncs_rd_pulse a[23:0] ncs nrd_s etup nrd_pulse nrd_hold mck nrd d[7:0] ncs_rd_setup ncs_rd_pulse ncs_rd_hold nrd_cycle
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 504 27.9.1.4 null delay setup and hold if null setup and hold parameters are programmed for nrd and/o r ncs, nrd and ncs remain active continuously in case of consecutive read cycl es in the same memory (see figure 27-8 ). figure 27-8. no setup, no hold on nrd and ncs read signals 27.9.1.5 null pulse programming null pulse is not permitted. pulse must be at least set to 1. a null value leads to unpredictable behavior. 27.9.2 read mode as ncs and nrd waveforms are defined independently of one other, the smc needs to know when the read data is available on the data bus. the smc does not compar e ncs and nrd timings to know which signal rises first. the read_mode parameter in the smc_mode register of the corresponding chip select indicates which signal of nrd and ncs controls the read operation. 27.9.2.1 read is controlled by nrd (read_mode = 1): figure 27-9 shows the waveforms of a read operation of a typi cal asynchronous ram. the read data is available t pacc after the falling edge of nrd, and tu rns to ?z? after the rising edge of nrd. in this case, the read_mode must be set to 1 (read is controlled by nrd), to indicate that data is available wi th the rising edge of nrd. the smc samples the read data internally on the rising edge of master clock that generates the rising edge of nrd, whatever the programmed waveform of ncs may be. mck nrd_pulse ncs_rd_pulse nrd_cycle nrd_pulse nrd_pulse ncs_rd_pulse ncs_rd_pulse nrd_cycle nrd_cycle a[23:0] ncs nrd d[7:0]
505 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-9. read_mode = 1: data is sample d by smc before the rising edge of nrd 27.9.2.2 read is controlled by ncs (read_mode = 0) figure 27-10 shows the typical read cycle of an lcd module. the read data is valid t pacc after the falling edge of the ncs signal and remains valid until the rising edge of ncs. data must be sampled wh en ncs is raised. in that case, the read_mode must be set to 0 (read is controlle d by ncs): the smc internally samples the data on the rising edge of master clock that gener ates the rising edge of ncs, whatever the programmed waveform of nrd may be. figure 27-10. read_mode = 0: data is sampled by smc before the rising edge of ncs data sampling t pacc mck a[23:0] ncs nrd d[7:0] data sampling t pacc mck d[7:0] a[23:0] ncs nrd
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 506 27.9.3 write waveforms the write protocol is similar to the read protocol. it is depicted in figure 27-11 . the write cycle starts with the address setting on the memory address bus. 27.9.3.1 nwe waveforms the nwe signal is characterized by a setup timing, a pulse width and a hold timing. 1. nwe_setup: the nwe setup time is defined as th e setup of address and dat a before the nwe falling edge; 2. nwe_pulse: the nwe pulse length is the time between nwe falling edge and nwe rising edge; 3. nwe_hold: the nwe hold time is def ined as the hold time of address and data after the nwe rising edge. 27.9.3.2 ncs waveforms the ncs signal waveforms in write operation are not the same that those applied in read operations, but are separately defined: 1. ncs_wr_setup: the ncs setup time is defined as the setup time of address before the ncs falling edge. 2. ncs_wr_pulse: the ncs pulse le ngth is the time between ncs fa lling edge and ncs rising edge; 3. ncs_wr_hold: the ncs hold time is defined as the hold time of address after the ncs rising edge. figure 27-11. write cycle 27.9.3.3 write cycle the write_cycle time is defined as the to tal duration of the write cycle, that is , from the time where address is set on the address bus to the point where address may change. the total write cy cle time is equal to: nwe_cycle = nwe_setup + nwe_pulse + nwe_hold = ncs_wr_setup + ncs_wr_pulse + ncs_wr_hold a [23:0] ncs nwe_s etup nwe_pulse nwe_hold mck nwe ncs_wr_setup ncs_wr_pulse ncs_wr_hold nwe_cycle
507 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 all nwe and ncs (write) timings are defined separately fo r each chip select as an integer number of master clock cycles. to ensure that the nwe and ncs timings are coher ent, the user must define the total write cycle instead of the hold timing. this implicit ly defines the nwe hold time and ncs (write) hold times as: nwe_hold = nwe_cycle - nwe_setup - nwe_pulse ncs_wr_hold = nwe_cycle - ncs_wr_setup - ncs_wr_pulse 27.9.3.4 null delay setup and hold if null setup parameters are programmed for nwe and/or ncs, nwe and/or ncs remain active continuously in case of consecutive write cycles in the same memory (see figure 27-12 ). however, for devices that perform write operations on the rising edge of nwe or ncs, such as sram, either a setup or a hold must be programmed. figure 27-12. null setup and hold values of ncs and nwe in write cycle 27.9.3.5 null pulse programming null pulse is not permitted. pulse must be at least set to 1. a null value leads to unpredictable behavior. 27.9.4 write mode the write_mode parameter in the smc_mode register of the corresponding chip se lect indicates which signal controls the write operation. 27.9.4.1 write is controlled by nwe (write_mode = 1): figure 27-13 shows the waveforms of a write operation with write_mode set to 1. the data is put on the bus during the pulse and hold steps of the nwe signal. the inte rnal data buffers are switched to output mode after the nwe_setup time, and until the end of the write cycl e, regardless of the pr ogrammed waveform on ncs. ncs mck nwe d[7:0] nwe_pulse ncs_wr_pulse nwe_cycle nwe_pulse ncs_wr_pulse nwe_cycle nwe_pulse ncs_wr_pulse nwe_cycle a [23:0]
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 508 figure 27-13. write_mode = 1. the write operation is controlled by nwe 27.9.4.2 write is controlled by ncs (write_mode = 0) figure 27-14 shows the waveforms of a write operation with write_mode set to 0. the data is put on the bus during the pulse and hold steps of the ncs signal. the inte rnal data buffers are switch ed to output mode after the ncs_wr_setup time, and until the end of the write cycle, regardless of the programmed waveform on nwe. figure 27-14. write_mode = 0. the write operation is controlled by ncs 27.9.5 write protected registers to prevent any single software error that may corrupt smc behavior, the registers listed below can be write- protected by setting the wpen bit in the sm c write protect mode register (smc_wpmr). if a write access in a writ e-protected register is detected, then th e wpvs flag in the smc write protect status register (smc_wpsr) is set and the field wpvsrc indicates in which register the write access has been attempted. the wpvs flag is automatically re set after reading the smc write pr otect status register (smc_wpsr). list of the write-protected registers: ? section 27.16.1 ?smc setup register? ? section 27.16.2 ?smc pulse register? mck d[7:0] ncs a [23:0] nwe mck d[7:0] ncs nwe a [23:0]
509 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? section 27.16.3 ?smc cycle register? ? section 27.16.4 ?smc mode register? 27.9.6 coding timing parameters all timing parameters are defined for one chip select an d are grouped together in one smc_register according to their type. the smc_setup register groups the de finition of all setup parameters: ? nrd_setup, ncs_rd_setup, nwe_setup, ncs_wr_setup the smc_pulse register groups the definition of all pulse parameters: ? nrd_pulse, ncs_rd_pulse, nwe_pulse, ncs_wr_pulse the smc_cycle register groups the de finition of all cycle parameters: ? nrd_cycle, nwe_cycle table 27-4 shows how the timing parameters are coded and their permitted range. 27.9.7 reset values of timing parameters table 27-5 gives the default value of timing parameters at reset. 27.9.8 usage restriction the smc does not check the validity of the user-programmed parameters. if the sum of setup and pulse parameters is larger than the corresponding cycle paramet er, this leads to unpredictable behavior of the smc. for read operations: null but positive setup and hold of address and nrd and/ or ncs can not be guaranteed at the memory interface because of the propagation delay of theses signals thr ough external logic and pads. if positive setup and hold values must be verified, then it is st rictly recommended to program non-null values so as to cover possible skews between address, ncs and nrd signals. table 27-4. coding and range of timing parameters coded value number of bits effective value permitted range coded value effective value setup [5:0] 6 128 x setup[5] + setup[4:0] 0 31 0 128+31 pulse [6:0] 7 256 x pulse[6] + pulse[5:0] 0 63 0 256+63 cycle [8:0] 9 256 x cycle[8:7] + cycle[6:0] 0 127 0 256+127 0 512+127 0 768+127 table 27-5. reset values of timing parameters register reset value definition smc_setup 0x01010101 all setup timings are set to 1. smc_pulse 0x01010101 all pulse timings are set to 1. smc_cycle 0x00030003 the read and write operations last 3 master clock cycles and provid e one hold cycle. write_mode 1 write is controlled with nwe. read_mode 1 read is controlled with nrd.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 510 for write operations: if a null hold value is programmed on nwe, the smc can guarantee a positive hold of address and ncs signal after the rising edge of nwe. this is true for write_mode = 1 only. see ?early read wait state? on page 511 . for read and write operations: a null value for pulse parameters is forbidden and may lead to unpredictable behavior. in read and write cycles, the setup and hold time parameters are defined in reference to the address bus. for external devices that require setup and hold time be tween ncs and nrd signals (read), or between ncs and nwe signals (write), these se tup and hold times must be converted into setup and hold times in reference to the address bus. 27.10 scrambling/un scrambling function the external data bus d[15:0] can be scrambled in order to prevent intellectual property data located in off-chip memories from being easily recovered by analyzing data at the package pin level of either microcontroller or memory device. the scrambling and unscrambling are performed on-the-fly without additional wait states. the scrambling method depends on two user-configurab le key registers, smc_key1 and sm c_key2. these key registers are only accessible in write mode. the key must be securely stored in a reliable non-volat ile memory in order to reco ver data from the off-chip memory. any data scrambled wit h a given key cannot be recovered if the key is lost. the scrambling/unscrambling function can be enabled or disabled by programming the smc_ocms register. when multiple chip selects are handled, it is possible to configure the scrambling function per chip select using the ocms field in the smc_ocms registers. 27.11 automatic wait states under certain circumstances, the smc automatically inserts idle cycles between accesses to avoid bus contention or operation conflict. 27.11.1 chip select wait states the smc always inserts an idle cycle be tween 2 transfers on separate chip se lects. this idle cycle ensures that there is no bus contention between the de-activation of one device and the activation of the next one. during chip select wait state, all control lines are turned inactive: nwr, ncs[0..3], nrd lines are all set to 1. figure 27-15 illustrates a chip select wait state between access on chip select 0 and chip select 2.
511 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-15. chip select wait state between a read access on ncs0 and a write access on ncs2 27.11.2 early read wait state in some cases, the smc inse rts a wait state cycle between a write access and a read access to allow time for the write cycle to end before the subsequent read cycle begins. this wait state is not generated in addition to a chip select wait state. the early read cycle thus only oc curs between a write and read access to the same memory device (same chip select). an early read wait state is auto matically inserted if at least one of the following conditions is valid: ? if the write cont rolling signal has no hold time and the read controlling signal has no setup time ( figure 27- 16 ). ? in ncs write controlled mode (write_mode = 0), if there is no hold timing on the ncs signal and the ncs_rd_setup parameter is set to 0, regardless of the read mode ( figure 27-17 ). the write operation must end with a ncs rising edge. without an early read wait state, the write oper ation could not complete properly. ? in nwe controlled mode (write_mode = 1) and if there is no hold timing (nwe_hold = 0), the feedback of the write control signal is used to control address, data, and chip select lines. if the external write control signal is not inactivated as expected due to load ca pacitances, an early read wait state is inserted and address, data and control signals are maintained one more cycle. see figure 27-18 . a[23:0] ncs0 nrd_cycle chip select wait state nwe_cycle mck ncs2 nrd nwe d[7:0] read to write wait state
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 512 figure 27-16. early read wait state: write wit h no hold followed by read with no setup figure 27-17. early read wait state: ncs controlled write with no hold followed by a read with no ncs setup write cycle early read wait state mck nrd nwe read cycle no setup no hold d[7:0] a[23:0] write cycle (write_mode = 0) early read wait state mck nrd ncs read cycle no setup no hold d[7:0] a[23:0] (read_mode = 0 or read_mode = 1)
513 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-18. early read wait state: nwe-controlled writ e with no hold followed by a read with one set-up cycle 27.11.3 reload user configuration wait state the user may change any of the configuration parameters by writing t he smc user interface. when detecting that a new user configuration has been written in the user interface, the smc inserts a wait state before starting the next access. the so called ?reload user configuration wait state? is used by the smc to load the new set of parameters to apply to next accesses. the reload configuration wait state is not applied in addition to the chip sele ct wait state. if accesses before and after re-programming the user interface are made to different devices (chip selects), then one single chip select wait state is applied. on the other hand, if accesses before and after writing the user interface are made to the same device, a reload configuration wait state is inserted, even if the change does not concern the current chip select. 27.11.3.1user procedure to insert a reload configuration wait state, the smc detects a write access to any smc_mode register of the user interface. if the user only m odifies timing registers (smc_setup, smc_pulse, smc_cycle registers) in the user interface, he must validate the modification by writing the smc_mode, even if no change was made on the mode parameters. the user must not change the configuration parameters of an smc chip select (set up, pulse, cycle, mode) if accesses are performed on this cs during the modification. any change of the chip select parameters, while fetching the code from a memory connected on this cs, ma y lead to unpredictable behavior. the instructions used to modify the parameters of an smc chip select c an be executed from the internal ram or from a memory connected to another cs. a [25:2] write cycle (write_mode = 1) early read wait state mck nrd internal write controlling signal external write controlling signal (nwe) d[7:0] read cycle no hold read setup = 1 (read_mode = 0 or read_mode = 1)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 514 27.11.3.2slow clock mode transition a reload configuration wa it state is also inserted when the slow clock mode is entered or exited, after the end of the current transfer (see ?slow clock mode? on page 525 ). 27.11.4 read to write wait state due to an internal mechanism, a wait cycle is always inserted between cons ecutive read and write smc accesses. this wait cycle is referred to as a read to write wait state in this document. this wait cycle is applied in addition to chip select and reload user configur ation wait states when they are to be inserted. see figure 27-15 on page 511 .
515 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.12 data float wait states some memory devices are slow to release the external bus. for such devices, it is necessary to add wait states (data float wait states) after a read access: ? before starting a read access to a different external memory ? before starting a write access to the same device or to a different external one. the data float output time (t df ) for each external memory device is programmed in the tdf_cycles field of the smc_mode register for the corresponding chip select. the value of tdf_cycles indicates the number of data float wait cycles (between 0 and 15) before the external device releases the bus, and represents the time allowed for the data output to go to high impedance after the memory is disabled. data float wait states do not delay internal memory acce sses. hence, a single access to an external memory with long t df will not slow down the execution of a program from internal memory. the data float wait states m anagement depends on the read_mode and t he tdf_mode fields of the smc_mode register for the corresponding chip select. 27.12.1 read_mode setting the read_mode to 1 indicates to the smc that the nrd signal is res ponsible for turning off the tri-state buffers of the external memory device. the data float peri od then begins after the rising edge of the nrd signal and lasts tdf_cycles mck cycles. when the read operation is controlled by the ncs signal (read_mode = 0), the tdf field gives the number of mck cycles during which the data bus rema ins busy after the rising edge of ncs. figure 27-19 illustrates the data float period in nrd-cont rolled mode (read_mode =1), assuming a data float period of 2 cycles (tdf_cycles = 2). figure 27-20 shows the read operation when controlled by ncs (read_mode = 0) and the tdf_cycles parameter equals 3. figure 27-19. tdf period in nrd controlled read access (tdf = 2) ncs nrd controlled read operation tpacc mck nrd d[7:0] tdf = 2 clock cycles a[23:0]
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 516 figure 27-20. tdf period in ncs controlled read operation (tdf = 3) 27.12.2 tdf optimization enabled (tdf_mode = 1) when the tdf_mode of the smc_mode register is set to 1 (tdf optim ization is enabled), the smc takes advantage of the setup period of the next access to op timize the number of wait states cycle to insert. figure 27-21 shows a read access controlled by nrd, followed by a write access controlled by nwe, on chip select 0. chip select 0 has been programmed with: nrd_hold = 4; read_mode = 1 (nrd controlled) nwe_setup = 3; write_mo de = 1 (nwe controlled) tdf_cycles = 6; tdf_mode = 1 (optimization enabled). ncs tdf = 3 clock cycles tpacc mck d[7:0] ncs controlled read operation a[23:0] nrd
517 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-21. tdf optimization: no tdf wait states are inser ted if the tdf period is over when the next access begins 27.12.3 tdf optimization disabled (tdf_mode = 0) when optimization is disabled, tdf wait states are inserted at the end of the read transfer, so that the data float period is ended when th e second access begins. if the hold period of the read1 controlling signal overlaps the data float period, no additional tdf wait states will be inserted. figure 27-22 , figure 27-23 and figure 27-24 illustrate the cases: ? read access followed by a read access on another chip select, ? read access followed by a write access on another chip select, ? read access followed by a write a ccess on the same chip select, with no tdf optimization. ncs0 mck nrd nwe d[7:0] read to write wait state tdf_cycles = 6 read access on ncs0 (nrd controlled) nrd_hold= 4 nwe_setup= 3 write access on ncs0 (nwe controlled)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 518 figure 27-22. tdf optimization disabled (tdf mode = 0): tdf wait states between 2 read accesses on different chip selects figure 27-23. tdf mode = 0: tdf wait states between a read and a write access on different chip selects tdf_cycles = 6 tdf_cycles = 6 tdf_mode = 0 a[ 23:0] read1 cycle chip select wait state mck read1 controlling signal (nrd) read2 controlling signal (nrd) d[7:0] read1 hold = 1 read 2 cycle read2 setup = 1 5 tdf wait states (optimization disabled) tdf_cycles = 4 tdf_cycles = 4 tdf_mode = 0 (optimization disabled) a [23:0] read1 cycle chip select wait state read to write wait state mck read1 controlling signal (nrd) write2 controlling signal (nwe) d[7:0] read1 hold = 1 write2 cycle write2 setup = 1 2 tdf wait states
519 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-24. tdf mode = 0: tdf wait states between read and write accesses on the same chip select 27.13 external wait any access can be extended by an external device using the nwait inpu t signal of the smc. the exnw_mode field of the smc_mode register on the corresponding chip select must be set either to ?10? (frozen mode) or ?11? (ready mode). when the exnw_mode is set to ?00? (d isabled), the nwait signal is simply ignored on the corresponding chip select. the nwait signal delays the re ad or write operation in regards to the read or write controlling signal, depending on the read and write modes of t he corresponding chip select. 27.13.1 restriction when one of the exnw_mode is enabled, it is mandatory to program at least one hold cycle for the read/write controlling signal. for that reason, the nwait signal cannot be used in page mode ( ?asynchronous page mode? on page 527 ), or in slow clock mode ( ?slow clock mode? on page 525 ). the nwait signal is assumed to be a response of the external device to the read/write request of the smc. then nwait is examined by the smc only in the pulse state of the read or write controlling signal. the assertion of the nwait signal outside the expected pe riod has no impact on smc behavior. tdf_cycles = 5 tdf_cycles = 5 tdf_mode = 0 (optimization disabled) a [23:0] read1 cycle read to write wait state mck read1 controlling signal (nrd) write2 controlling signal (nwe) d[7:0] read1 hold = 1 write2 cycle write2 setup = 1 4 tdf wait states
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 520 27.13.2 frozen mode when the external device asserts the nwait signal (active low), and after internal synchronization of this signal, the smc state is frozen, i.e., smc internal counters are frozen, and all control signals remain unchanged. when the resynchronized nwait signal is d easserted, the smc completes the access, resuming the access from the point where it was stopped. see figure 27-25 . this mode must be selected when the external device uses the nwait signal to delay the access and to freeze the smc. the assertion of the nwait sign al outside the expected period is ignored as illustrated in figure 27-26 . figure 27-25. write access with nwait asse rtion in frozen mode (exnw_mode = 10) exnw_mode = 10 (frozen) write_mode = 1 (nwe_controlled) nwe_pulse = 5 ncs_wr_pulse = 7 a [23:0] mck nwe ncs 432 1 110 1 4 5 63 2 2 2 2 1 0 write cycle d[7:0] nwait frozen state internally synchronized nwait signal
521 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-26. read access with nwait assertion in frozen mode (exnw_mode = 10) exnw_mode = 10 (frozen) read_mode = 0 (ncs_controlled) nrd_pulse = 2, nrd_hold = 6 ncs_rd_pulse =5, ncs_rd_hold =3 a [23:0] mck ncs nrd 10 4 3 4 3 2 555 22 0 210 210 1 read cycle assertion is ignored nwait internally synchronized nwait signal frozen state
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 522 27.13.3 ready mode in ready mode (exnw_mode = 11), the smc behaves differently. normally, the smc begins the access by down counting the setup and pulse counter s of the read/write controlling signal. in the last cycle of the pulse phase, the resynchronized nwait signal is examined. if asserted, the smc suspends the access as shown in figure 27-27 and figure 27-28 . after deassertion, the access is completed: the hold step of the access is performed. this mode must be selected when the external devi ce uses deassertion of the nwai t signal to indicate its ability to complete the read or write operation. if the nwait signal is deasserted before the end of the pulse, or asserted after the end of the pulse of the controlling read/write signal, it has no impact on the a ccess length as shown in figure 27-28 . figure 27-27. nwait assertion in write access: ready mode (exnw_mode = 11) exnw_mode = 11 (ready mode) write_mode = 1 (nwe_controlled) nwe_pulse = 5 ncs_wr_pulse = 7 a [23:0] mck nwe ncs 4 3 21 00 0 4 5 6 3 21110 write cycle d[7:0] nwait internally synchronized nwait signal wait state
523 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-28. nwait assertion in read access: ready mode (exnw_mode = 11) exnw_mode = 11(ready mode) read_mode = 0 (ncs_controlled) nrd_pulse = 7 ncs_rd_pulse =7 a[23:0] mck ncs nrd 4 5 6 3 200 0 1 4 5 6 3 21 1 read cycle assertion is ignored nwait internally synchronized nwait signal wait state assertion is ignored
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 524 27.13.4 nwait latency and read/write timings there may be a latency between the asse rtion of the read/write controlling si gnal and the assertion of the nwait signal by the device. the programmed pulse length of t he read/write controlling signal must be at least equal to this latency plus the 2 cycles of resynchronization + 1 cycle. otherwise, the smc may enter the hold state of the access without detecting the nwait signal assertion. this is true in frozen mode as well as in ready mode. this is illustrated on figure 27-29 . when exnw_mode is enabled (ready or fr ozen), the user must program a pulse length of the read and write controlling signal of at least: minimal pulse length = nwait latency + 2 resynchronization cycles + 1 cycle figure 27-29. nwait latency exnw_mode = 10 or 11 read_mode = 1 (nrd_controlled) nrd_pulse = 5 a [23:0] mck nrd 43 210 0 0 read cycle minimal pulse length nwait latency nwait intenally synchronized nwait signal wait state 2 cycle resynchronization
525 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.14 slow clock mode the smc is able to automatically apply a set of ?slow clock mode? read/write waveforms when an internal signal driven by the power management controller is asserted because mck has been turned to a very slow clock rate (typically 32khz clock rate). in this mode, the user-p rogrammed waveforms are ignored and the slow clock mode waveforms are applied. this mode is provided so as to avoid reprogramming the user interface with appropriate waveforms at very slow clock rate . when activated, the slow mode is active on all chip selects. 27.14.1 slow clock mode waveforms figure 27-30 illustrates the read and write oper ations in slow clock mode. they are valid on all chip selects. table 27-6 indicates the value of read and write parameters in slow clock mode. figure 27-30. read/write cycles in slow clock mode a[ 23:0] ncs 1 mck nwe 1 1 nwe_cycle = 3 a [23:0] mck nrd nrd_cycle = 2 1 1 ncs slow clock mode write slow clock mode read table 27-6. read and write timing parameters in slow clock mode read parameters duration (cycles) write parameters duration (cycles) nrd_setup 1 nwe_setup 1 nrd_pulse 1 nwe_pulse 1 ncs_rd_setup 0 ncs_wr_setup 0 ncs_rd_pulse 2 ncs_wr_pulse 3 nrd_cycle 2 nwe_cycle 3
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 526 27.14.2 switching from (to) slow cl ock mode to (from) normal mode when switching from slow clock mode to normal mode, the current slow clock mode transfer is completed at high clock rate, with the set of slow clock mode parameters.see figure 27-31 on page 526 . the external device may not be fast enough to support such timings. figure 27-32 illustrates the recommended pr ocedure to properly switch from one mode to the other. figure 27-31. clock rate transition occurs wh ile the smc is performing a write operation figure 27-32. recommended procedure to switch from slow clock mode to normal mode or from normal mode to slow clock mode a [23:0] ncs 1 mck nwe 1 1 nwe_cycle = 3 slow clock mode write slow clock mode internal signal from pmc 11 1 2 3 2 nwe_cycle = 7 normal mode write slow clock mode transition is detected: reload configuration wait state this write cycle finishes with the slow clock mode set of parameters after the clock rate transition slow clock mode write a [23:0] ncs 1 mck nwe 1 1 slow clock mode write slow clock mode internal signal from pmc 2 3 2 normal mode write idle state reload configuration wait state
527 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.15 asynchronous page mode the smc supports asynchronous burst reads in page m ode, providing that the page mode is enabled in the smc_mode register (pmen field). the page size must be configured in the smc_mode register (ps field) to 4, 8, 16 or 32 bytes. the page defines a set of consecutive bytes into memory. a 4-byte page (resp. 8-, 16-, 32-byte page) is always aligned to 4-byte boundaries (resp. 8-, 16-, 32-byte bou ndaries) of memory. the msb of data address defines the address of the page in memory, the lsb of address defi ne the address of the data in the page as detailed in table 27-7 . with page mode memory devices, the first access to one page (t pa ) takes longer than the subsequent accesses to the page (t sa ) as shown in figure 27-33 . when in page mode, the smc enables the user to define different read timings for the first access within one page, and next accesses within the page. note: 1. ?a? denotes the addre ss bus of the memory device. 27.15.1 protocol and timings in page mode figure 27-33 shows the nrd and ncs timings in page mode access. figure 27-33. page mode read protocol (address msb and lsb are defined in table 27-7 ) the nrd and ncs signals are held low dur ing all read transfers, whatever the programmed values of the setup and hold timings in the user interface may be. moreover , the nrd and ncs timings are identical. the pulse length of the first access to the page is defined with the ncs_rd_pulse field of the smc_pulse register. the pulse length of subsequent accesses within the page are defined using the nrd_pulse parameter. table 27-7. page address and data address within a page page size page address (1) data address in the page 4 bytes a[23:2] a[1:0] 8 bytes a[23:3] a[2:0] 16 bytes a[23:4] a[3:0] 32 bytes a[23:5] a[4:0] a[msb] ncs mck nrd d[7:0] ncs_rd_pulse nrd_pulse nrd_pulse tsa tpa tsa a[lsb]
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 528 in page mode, the programming of the read timings is described in table 27-8 : the smc does not check the coherency of timings. it will always apply the ncs_rd_pulse timings as page access timing (t pa ) and the nrd_pulse for accesses to the page (t sa ), even if the programmed value for t pa is shorter than the programmed value for t sa . 27.15.2 page mode restriction the page mode is not compatible with the use of the nwait signal. using the page mode and the nwait signal may lead to unpredictable behavior. 27.15.3 sequential and non-sequential accesses if the chip select and the msb of addresses as defined in table 27-7 are identical, then the current access lies in the same page as the previous one, and no page break occurs. using this information, all data within the same page, sequential or not sequential, are accessed with a minimum access time (t sa ). figure 27-34 illustrates access to an 8-bit memory device in page mode, with 8-byte pages. access to d1 causes a page ac cess with a long access time (t pa ). accesses to d3 and d7, though they are not sequential accesses, only re quire a short access time (t sa ). if the msb of addresses are different, the smc performs the access of a new page. in the same way, if the chip select is different from the previous access, a page br eak occurs. if two sequential accesses are made to the page mode memory, but separated by an other internal or ex ternal peripheral access, a page break occurs on the second access because the chip select of the device was deasserted between both accesses. table 27-8. programming of read timings in page mode parameter value definition read_mode ?x? no impact ncs_rd_setup ?x? no impact ncs_rd_pulse t pa access time of first access to the page nrd_setup ?x? no impact nrd_pulse t sa access time of subsequent accesses in the page nrd_cycle ?x? no impact
529 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 27-34. access to non-sequential data within the same page a [23:3] a[2], a1, a0 ncs mck nrd page address a1 a3 a7 d[7:0] ncs_rd_pulse nrd_pulse nrd_pulse d1 d3 d7
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 530 27.16 static memory controll er (smc) user interface the smc is programmed using the registers listed in table 27-9 . for each chip select, a set of 4 registers is used to pro- gram the parameters of the external device connected on it. in table 27-9 , ?cs_number? denotes th e chip select number. 16 bytes (0x10) are required per chip select. the user must complete writing the configuration by writing any one of the smc_mode registers. table 27-9. register mapping offset register name access reset 0x10 x cs_number + 0x00 smc setup register smc_setup read/write 0x01010101 0x10 x cs_number + 0x04 smc pulse register smc_pulse read/write 0x01010101 0x10 x cs_number + 0x08 smc cycle register smc_cycle read/write 0x00030003 0x10 x cs_number + 0x0c smc mode register smc_mode read/write 0x10000003 0x80 smc ocms mode register smc_ocms read/write 0x00000000 0x84 smc ocms key1 register smc_key1 write once 0x00000000 0x88 smc ocms key2 register smc_key2 write once 0x00000000 0xe4 smc write protect mode register smc_wpmr read/write 0x00000000 0xe8 smc write protect status register smc_wpsr read-only 0x00000000 0xec-0xfc reserved ? ? ?
531 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.16.1 smc setup register name: smc_setup[0..3] address: 0x400e0000 (0)[0], 0x400e0010 (0)[1] , 0x400e0020 (0)[2], 0x400e0030 (0)[3] 0x4801c000 (1)[0], 0x4801c010 (1)[1], 0x 4801c020 (1)[2], 0x4801c030 (1)[3] access: read/write ? nwe_setup: nwe setup length the nwe signal setup length is defined as: nwe setup length = (128 * nwe_setup[5] + nwe_set up[4:0]) clock cycles ? ncs_wr_setup: ncs setup length in write access in write access, the ncs signal setup length is defined as: ncs setup length = (128* ncs_wr_setup [5] + ncs_wr_setup[4:0]) clock cycles ? nrd_setup: nrd setup length the nrd signal setup length is defined in clock cycles as: nrd setup length = (128* nrd_setup [5] + nrd_setup[4:0 ]) clock cycles ? ncs_rd_setup: ncs setup length in read access in read access, the ncs signal setup length is defined as: ncs setup length = (128* ncs_rd_setup [5] + ncs_rd_setup[4:0]) clock cycles 31 30 29 28 27 26 25 24 ? ? ncs_rd_setup 23 22 21 20 19 18 17 16 ? ? nrd_setup 15 14 13 12 11 10 9 8 ? ? ncs_wr_setup 76543210 ? ? nwe_setup
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 532 27.16.2 smc pulse register name: smc_pulse[0..3] address: 0x400e0004 (0)[0], 0x400e0014 (0)[1] , 0x400e0024 (0)[2], 0x400e0034 (0)[3] 0x4801c004 (1)[0], 0x4801c014 (1)[1], 0x 4801c024 (1)[2], 0x4801c034 (1)[3] access: read/write ? nwe_pulse: nwe pulse length the nwe signal pulse length is defined as: nwe pulse length = (256* nwe_pul se[6] + nwe_pulse[5:0]) clock cycles the nwe pulse length must be at least 1 clock cycle. ? ncs_wr_pulse: ncs pulse length in write access in write access, the ncs signal pulse length is defined as: ncs pulse length = (256* ncs_wr_pulse[6] + ncs_wr_pulse[5:0]) clock cycles the ncs pulse length must be at least 1 clock cycle. ? nrd_pulse: nrd pulse length in standard read access, the nrd signal puls e length is defined in clock cycles as: nrd pulse length = (256* nrd_pulse[6] + nrd_pulse[5:0]) clock cycles the nrd pulse length must be at least 1 clock cycle. in page mode read access, the nrd_pulse parameter defines the duration of the subseque nt accesses in the page. ? ncs_rd_pulse: ncs puls e length in read access in standard read access, the ncs signal pulse length is defined as: ncs pulse length = (256* ncs_rd_pulse[6] + ncs_rd_ pulse[5:0]) clock cycles the ncs pulse length must be at least 1 clock cycle. in page mode read access, the ncs_rd_pulse parameter defines the duration of the first access to one page. 31 30 29 28 27 26 25 24 ? ncs_rd_pulse 23 22 21 20 19 18 17 16 ? nrd_pulse 15 14 13 12 11 10 9 8 ? ncs_wr_pulse 76543210 ?n w e _ p u l s e
533 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.16.3 smc cycle register name: smc_cycle[0..3] address: 0x400e0008 (0)[0], 0x400e0018 (0)[1] , 0x400e0028 (0)[2], 0x400e0038 (0)[3] 0x4801c008 (1)[0], 0x4801c018 (1)[1], 0x 4801c028 (1)[2], 0x4801c038 (1)[3] access: read/write ? nwe_cycle: total write cycle length the total write cycle length is t he total duration in clock cycles of the write cy cle. it is equal to the sum of the setup, pul se and hold steps of the nwe and ncs signals. it is defined as: write cycle length = (nwe_cycle[8:7 ]*256 + nwe_cycle[6:0]) clock cycles ? nrd_cycle: total read cycle length the total read cycle length is the total duration in clock cycles of the read cycl e. it is equal to the sum of the setup, pulse and hold steps of the nrd and nc s signals. it is defined as: read cycle length = (nrd_cycle[8:7] *256 + nrd_cycle[6:0]) clock cycles 31 30 29 28 27 26 25 24 ??????? nrd_cycle 23 22 21 20 19 18 17 16 nrd_cycle 15 14 13 12 11 10 9 8 ???????n w e _ c y c l e 76543210 nwe_cycle
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 534 27.16.4 smc mode register name: smc_mode[0..3] address: 0x400e000c (0)[0], 0x400e001c (0)[1 ], 0x400e002c (0)[2], 0x400e003c (0)[3] 0x4801c00c (1)[0], 0x4801c0 1c (1)[1], 0x4801c02c (1 )[2], 0x4801c03c (1)[3] access: read/write ? read_mode: read mode 1: the read operation is controlled by the nrd signal. ? if tdf cycles are programmed, the external bus is marked busy after the rising edge of nrd. ? if tdf optimization is enabled (tdf_mode =1), tdf wait states are inserted after the setup of nrd. 0: the read operation is controlled by the ncs signal. ? if tdf cycles are programmed, the external bus is marked busy after the rising edge of ncs. ? if tdf optimization is enabled (tdf_mode =1), tdf wait states are inserted after the setup of ncs. ? write_mode: write mode 1: the write operation is controlled by the nwe signal. ? if tdf optimization is enabled (tdf_mode =1), tdf wa it states will be insert ed after the setup of nwe. 0: the write operation is c ontrolled by the ncs signal. ? if tdf optimization is enabled (tdf_mode =1), tdf wa it states will be insert ed after the setup of ncs. ? exnw_mode: nwait mode the nwait signal is used to extend the current read or write si gnal. it is only taken into account during the pulse phase of the read and write contro lling signal. when the use of nwai t is enabled, at least one cyc le hold duration must be pro- grammed for the read and write controlling signal. ? disabled mode: the nwait input signal is ignored on the corresponding chip select. ? frozen mode: if asserted, the nwait signal freezes the current read or write cycle. after deassertion, the read/write cycle is resumed from the point where it was stopped. 31 30 29 28 27 26 25 24 ?? p s ???p m e n 23 22 21 20 19 18 17 16 ? ? ? tdf_mode tdf_cycles 15 14 13 12 11 10 9 8 ???d b w???b a t 76543210 ? ? exnw_mode ? ? write_mode read_mode value name description 0 disabled disabled 1? reserved 2 frozen frozen mode 3 ready ready mode
535 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? ready mode: the nwait sign al indicates the availability of the external de vice at the end of the pulse of the controlling read or write signal, to complete the access. if high, the access normally completes. if low, the access is extended until nwait returns high. ? bat: byte access type this field is used only if dbw defines a 16-bit data bus. ? dbw: data bus width ? tdf_cycles: data float time this field gives the integer number of clock cycles required by the external device to release the data after the rising edge of the read controlling signal. the smc always provide one full cycle of bus turn around after the tdf_cycles period. the external bus cannot be used by another chip select during tdf_cycles + 1 cycles. from 0 up to 15 tdf_cycles can be set. ? tdf_mode: tdf optimization 1: tdf optimization is enabled. ? the number of tdf wait states is optimized using the setup period of the next read/write access. 0: tdf optimization is disabled. ? the number of tdf wait states is inserted before the next access begins. ? pmen: page mode enabled 1: asynchronous burst read in page mode is applied on the corresponding chip select. 0: standard read is applied. ? ps: page size if page mode is enabled, this field indicates the size of the page in bytes. value name description 0 byte_select byte select access type: - write operation is controlled using ncs, nwe, nbs0, nbs1. - read operation is controlled using ncs, nrd, nbs0, nbs1. 1 byte_write byte write access type: - write operation is controlled using ncs, nwr0, nwr1. - read operation is controlled using ncs and nrd. value name description 0 8_bit 8-bit data bus 1 16_bit 16-bit data bus value name description 0 4_byte 4-byte page 1 8_byte 8-byte page 2 16_byte 16-byte page 3 32_byte 32-byte page
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 536 27.16.5 smc ocms mode register name: smc_ocms address: 0x400e0080 (0), 0x4801c080 (1) access: read/write ? csxse: chip select (x = 0 to 3) scrambling enable 0: disable scrambling for csx. 1: enable scrambling for csx. ? smse: static memory contro ller scrambling enablesam4c0x0 0030003cs0secs1secs1secs2secs3se 0: disable scrambling for smc access. 1: enable scrambling for smc access. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???? c s 3 s ec s 2 s ec s 1 s ec s 0 s e 15 14 13 12 11 10 9 8 ???????? 76543210 ???????s m s e
537 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.16.6 smc ocms key1 register name: smc_key1 address: 0x400e0084 (0), 0x4801c084 (1) access: write once ? key1: off chip memory scrambling (ocms) key part 1 when off chip memory scra mbling is enabled setting the smc_ocms and smc_timings registers in accordance, the data scrambling depends on key1 and key2 values. 31 30 29 28 27 26 25 24 key1 23 22 21 20 19 18 17 16 key1 15 14 13 12 11 10 9 8 key1 76543210 key1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 538 27.16.7 smc ocms key2 register name : smc_key2 address: 0x400e0088 (0), 0x4801c088 (1) access : write once ? key2: off chip memory scrambling (ocms) key part 2 when off chip memory scra mbling is enabled setting the smc_ocms and smc_timings registers in accordance, the data scrambling depends on key2 and key1 values. 31 30 29 28 27 26 25 24 key2 23 22 21 20 19 18 17 16 key2 15 14 13 12 11 10 9 8 key2 76543210 key2
539 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 27.16.8 smc write protect mode register name: smc_wpmr address: 0x400e00e4 (0), 0x4801c0e4 (1) access: read/write ? wpen: write protect enable 0: disables the write protect if wpkey co rresponds to 0x534d43 (?smc? in ascii). 1: enables the write protect if wpkey co rresponds to 0x534d43 (?smc? in ascii). protects the registers listed below: ? section 27.16.1 ?smc setup register? ? section 27.16.2 ?smc pulse register? ? section 27.16.3 ?smc cycle register? ? section 27.16.4 ?smc mode register? ? wpkey: write protect key should be written at value 0x534d43 (?smc? in ascii). writing an y other value in this field abor ts the write operation of the wpen bit. always reads as 0. 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 540 27.16.9 smc write protect status register name: smc_wpsr address: 0x400e00e8 (0), 0x4801c0e8 (1) access: read-only ? wpvs: write protect enable 0: no write protect violation has occurred sinc e the last read of the smc_wpsr register. 1: a write protect violation occu rred since the last read of the smc_wpsr re gister. if this violation is an unauthorized attempt to write a prot ected register, the asso ciated violation is reported into field wpvsrc. ? wpvsrc: write protect violation source when wpvs is active, this fiel d indicates the write-pr otected register (through address of fset or code) in which a write access has been attempted. note: reading smc_wpsr automatically clears all fields. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
541 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28. peripheral dma controller (pdc) 28.1 description the peripheral dma controller (pdc) transfers data between on-chip serial peripheral s and the target memories. the link between the pdc and a serial peripheral is operated by the ahb to apb bridge. the user interface of each pdc channel is integrated into the user interface of the peripheral it serves. the user interface of mono-directional channels (receive-only or tran smit-only) contains two 32-bit memory pointers and two 16-bit counters, one set (pointer, counter) for the current transfer and one set (pointer, counter) for the next transfer. the bidirectional channel user interface contai ns four 32-bit memory pointers and four 16-bit counters. each set (pointer, counter) is used by the current tr ansmit, next transmit, current receive and next receive. using the pdc decreases processor overhead by reduci ng its intervention during th e transfer. this lowers significantly the number of clock cycl es required for a data transfer, im proving microcontroller performance. to launch a transfer, the peripheral triggers its asso ciated pdc channels by using transmit and receive signals. when the programmed data is transferred, an end of transfer interrupt is generated by the peripheral itself. 28.2 embedded characteristics ? performs transfers to /from apb communication serial peripherals ? supports half-duplex and full-duplex peripherals
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 542 28.3 block diagram figure 28-1. block diagram pdc full duplex peripheral thr rhr pdc channel a pdc channel b control status & control control pdc channel c half duplex peripheral thr status & control receive or transmit peripheral rhr or thr control control rhr pdc channel d status & control
543 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28.4 functional description 28.4.1 configuration the pdc channel user interface enables the user to configure and control data transfers for each channel. the user interface of each pdc channel is integrated into the associated peripheral user interface. the user interface of a serial peripheral, whether it is full- or half-duplex, contains four 32-bit pointers (rpr, rnpr, tpr, tnpr) and four 16-bit counter registers (rcr, rncr, tcr, tncr). howeve r, the transmit and receive parts of each type are programmed differently: t he transmit and receive parts of a full-duplex peripheral can be programmed at the same time, whereas only one part (transmit or receive) of a half-duplex peripheral can be programmed at a time. 32-bit pointers define the access location in memory for the current and next transfer, whether it is for read (transmit) or write (receive). 16-bit counters define the size of the curr ent and next transfers. it is possible, at any moment, to read the number of transfers remaining for each channel. the pdc has dedicated status registers wh ich indicate if the transfer is enabled or disabled for each channel. the status for each channel is located in the associated peripheral status register . transfers can be enabled and/or disabled by setting txten/txtdis and rxten/rxtdis in the peripheral?s transfer control register. at the end of a transfer, the pdc channel sends status flags to its associated peripheral. these flags are visible in the peripheral status register (endrx, endtx, rxbuff, and txbufe). refer to section 28.4.3 and to the associated peripheral user interface. the peripheral where a pdc transfer is configured must have its peripheral clock enabled. the peripheral clock must be also enabled to access the pdc re gister set associated to this peripheral. 28.4.2 memory pointers each full-duplex peripheral is connected to the pdc by a receive channel and a transmit channel. both channels have 32-bit memory pointers that point to a receive area and to a transmit area, respectively, in the target memory. each half-duplex peripheral is connected to the pdc by a bidirectional channel. this channel has two 32-bit memory pointers, one for current transfer and the other for next transfer. these poin ters point to transmit or receive data depending on the operating mode of the peripheral. depending on the type of transfer (byt e, half-word or word), the memory pointer is incremented respectively by 1, 2 or 4 bytes. if a memory pointer address changes in the middle of a transfer, the pdc channel co ntinues operating using the new address. 28.4.3 transfer counters each channel has two 16-bit counters, one for the current transfer and the one for the next transfer. these counters define the size of data to be transferred by the channel. the current transfer counter is decremented first as the data addressed by the current memory pointer starts to be transferred. when the current transfer counter reaches zero, the channel checks its next transfer counter. if the value of th e next counter is zero, the channel stops transferring data and sets the app ropriate flag. if the next counter value is greater than zero, the values of the next pointer/next counter are copied into the current pointer/current counter and the channel resumes the transfer, whereas next pointer/next counter get zero/zero as values.at the end of this transfer, the pdc channel sets the appropriate flags in th e peripheral status register. the following list gives an overview of how status regi ster flags behave depending on the counters? values: ? endrx flag is set when the pdc receive co unter register (perip h_rcr) reaches zero. ? rxbuff flag is set when both periph_rcr and the pdc receive next counter register (periph_rncr) reach zero.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 544 ? endtx flag is set when the pdc transmit coun ter register (periph_tcr) reaches zero. ? txbufe flag is set when both periph_tcr and the pdc transmit next counte r register (periph_tncr) reach zero. these status flags are described in the peripheral status register (periph_ptsr). 28.4.4 data transfers the serial peripheral triggers its associated pdc channels? transfers us ing transmit enable (txen) and receive enable (rxen) flags in the transfer control register integrated in the peripheral?s user interface. when the peripheral receives external data, it sends a receive ready signal to its pdc receive channel which then requests access to the matrix. when access is granted, the pdc receive channel starts reading the peripheral receive holding register (rhr). the read data are stored in an internal buffer and then written to memory. when the peripheral is about to send data, it sends a transmit ready to its pdc transmit channel which then requests access to the matrix. when access is granted, the pdc transmit channel reads data from memory and transfers the data to the transmit hold ing register (thr) of its associated peripheral. the same peripheral sends data depending on its mechanism. 28.4.5 pdc flags and peripheral status register each peripheral connected to the pdc sends out receive ready and transmit ready flags and the pdc returns flags to the peripheral. all these flags are only vi sible in the peripheral?s status register. depending on whether the peripheral is half- or full-dupl ex, the flags belong to either one single channel or two different channels. 28.4.5.1 receive transfer end the receive transfer end flag is set when periph_rcr reaches zero and the last data has been transferred to memory. this flag is reset by writing a non-ze ro value to periph_rcr or periph_rncr. 28.4.5.2 transmit transfer end the transmit transfer end flag is set when periph_tcr reaches zero and the last data has been written to the peripheral thr. this flag is reset by writing a non-ze ro value to periph_tcr or periph_tncr. 28.4.5.3 receive buffer full the receive buffer full flag is set when periph_rcr reaches zero, with per iph_rncr also set to zero and the last data transferred to memory. this flag is reset by writing a non-ze ro value to periph_tcr or periph_tncr. 28.4.5.4 transmit buffer empty the transmit buffer empty flag is set when periph_tcr reaches zero, with periph_tncr also set to zero and the last data written to peripheral thr. this flag is reset by writing a non-ze ro value to periph_tcr or periph_tncr.
545 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28.5 peripheral dma controll er (pdc) user interface note: 1. periph: ten registers are mapped in the peripheral memory space at the same offset. these can be defined by the user depending on the function and the desired peripheral. table 28-1. register mapping offset register name access reset 0x00 receive pointer register periph (1) _rpr read/write 0 0x04 receive counter register periph_rcr read/write 0 0x08 transmit pointer register periph_tpr read/write 0 0x0c transmit counter register periph_tcr read/write 0 0x10 receive next pointer register periph_rnpr read/write 0 0x14 receive next counter register periph_rncr read/write 0 0x18 transmit next pointer register periph_tnpr read/write 0 0x1c transmit next counter register periph_tncr read/write 0 0x20 transfer control register periph_ptcr write-only 0 0x24 transfer status register periph_ptsr read-only 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 546 28.5.1 receive pointer register name: periph_rpr access: read/write ? rxptr: receive pointer register rxptr must be set to receive buffer address. when a half-duplex peripheral is connected to the pdc, rxptr = txptr. 31 30 29 28 27 26 25 24 rxptr 23 22 21 20 19 18 17 16 rxptr 15 14 13 12 11 10 9 8 rxptr 76543210 rxptr
547 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28.5.2 receive counter register name: periph_rcr access: read/write ? rxctr: receive counter register rxctr must be set to receive buffer size. when a half-duplex peripheral is c onnected to the pdc, rxctr = txctr. 0: stops peripheral data tr ansfer to the receiver. 1 - 65535: starts peripheral data transfer if the corresponding channel is active. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rxctr 76543210 rxctr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 548 28.5.3 transmit pointer register name: periph_tpr access: read/write ? txptr: transmit counter register txptr must be set to tr ansmit buffer address. when a half-duplex peripheral is connected to the pdc, rxptr = txptr. 31 30 29 28 27 26 25 24 txptr 23 22 21 20 19 18 17 16 txptr 15 14 13 12 11 10 9 8 txptr 76543210 txptr
549 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28.5.4 transmit counter register name: periph_tcr access: read/write ? txctr: transmit counter register txctr must be set to transmit buffer size. when a half-duplex peripheral is c onnected to the pdc, rxctr = txctr. 0: stops peripheral data tr ansfer to the transmitter. 1- 65535: starts peripheral data transfer if the corresponding channel is active. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txctr 76543210 txctr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 550 28.5.5 receive next pointer register name: periph_rnpr access: read/write ? rxnptr: receiv e next pointer rxnptr contains the next receive buffer address. when a half-duplex peripheral is conn ected to the pdc, rxnptr = txnptr. 31 30 29 28 27 26 25 24 rxnptr 23 22 21 20 19 18 17 16 rxnptr 15 14 13 12 11 10 9 8 rxnptr 76543210 rxnptr
551 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28.5.6 receive next counter register name: periph_rncr access: read/write ? rxnctr: receive next counter rxnctr contains the next receive buffer size. when a half-duplex peripheral is connected to the pdc, rxnctr = txnctr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rxnctr 76543210 rxnctr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 552 28.5.7 transmit next pointer register name: periph_tnpr access: read/write ? txnptr: transmit next pointer txnptr contains the next transmit buffer address. when a half-duplex peripheral is conn ected to the pdc, rxnptr = txnptr. 31 30 29 28 27 26 25 24 txnptr 23 22 21 20 19 18 17 16 txnptr 15 14 13 12 11 10 9 8 txnptr 76543210 txnptr
553 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28.5.8 transmit next counter register name: periph_tncr access: read/write ? txnctr: transmit counter next txnctr contains the next transmit buffer size. when a half-duplex peripheral is connected to the pdc, rxnctr = txnctr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txnctr 76543210 txnctr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 554 28.5.9 transfer control register name: periph_ptcr access: write-only ? rxten: receiver transfer enable 0: no effect. 1: enables pdc receiver channel requests if rxtdis is not set. when a half-duplex peripheral is connected to the pdc, enabling the receiver channel requests automatically disables the transmitter channel requests. it is forbidden to se t both txten and rxten for a half-duplex peripheral. ? rxtdis: receiver transfer disable 0: no effect. 1: disables the pdc receiver channel requests. when a half-duplex peripheral is connected to the pdc, disablin g the receiver channel requests also disables the transmit- ter channel requests. ? txten: transmitter transfer enable 0: no effect. 1: enables the pdc transmitter channel requests. when a half-duplex peripheral is connected to the pdc, it enables the transmitter channel requests only if rxten is not set. it is forbidden to set both txten and rxten for a half-duplex peripheral. ? txtdis: transmitter transfer disable 0: no effect. 1: disables the pdc transmitter channel requests. when a half-duplex peripheral is connecte d to the pdc, disabling the transmitter channel requests disables the receiver channel requests. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ??????t x t d i st x t e n 76543210 ??????r x t d i sr x t e n
555 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 28.5.10 transfer status register name: periph_ptsr access: read-only ? rxten: receiver transfer enable 0: pdc receiver channel requests are disabled. 1: pdc receiver channel requests are enabled. ? txten: transmitter transfer enable 0: pdc transmitter channel requests are disabled. 1: pdc transmitter channel requests are enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????t x t e n 76543210 ???????r x t e n
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 556 29. clock generator 29.1 description the clock generator user interface is embedded withi n the power management cont roller and is described in section 30.18 ?power management controller (pmc) user interface? . however, the clock generator registers are named ckgr_. 29.2 embedded characteristics the clock generator is made up of: ? a low-power 32768 hz slow cl ock oscillator with bypass mode ? a low-power rc oscillator ? a 3 to 20 mhz crystal or ceramic resonator-based oscillator, which can be bypassed. ? a factory-programmed fast rc oscillator. three output frequencies can be selected: 4/8/12 mhz. by default 4 mhz is selected. ? two programmable plls, (plla input from 32 khz, output clock range 8 mhz and pllb input from 3 to 32 mhz, output clock range 80 to 240 mhz), capable of providing the clock mck to the processor and to the peripherals. it provides the following clocks: ? slck, the slow clock, which is the on ly permanent clock within the system. ? mainck is the output of the main clock oscillator selection: either th e crystal or cerami c resonator-based oscillator or 4/8/12 mh z fast rc oscillator. ? pllack is the output of the 8 mhz programmable pll (plla). ? pllbck is the output of the divider and 80 to 240 mhz programmable pll (pllb).
557 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 29.3 block diagram figure 29-1. clock generator block diagram plla pllb and divider /2 plladiv2 pllbdiv2 main clock mainck plla clock pllack control status xin xout xin32 xout32 slck xtalsel (supply controller) pllb clock pllbck 0 1 0 1 3-20 mhz crystal or ceramic resonator oscillator embedded 4/8/12 mhz fast rc oscillator 32768 hz crystal oscillator embedded 32 khz rc oscillator srcb 1 0 clock generator slow clock power management controller ckgr_pllbr pmc_mckr moscsel ckgr_mor pmc_mckr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 558 29.4 slow clock the supply controller embeds a slow clock generator th at is supplied with the vddb u power supply. as soon as vddbu is supplied, both the crysta l oscillator and the embedded rc oscillator are powered up, but only the embedded rc oscillator is enabled. th is allows the slow clock to be valid in a short time (about 100 s). the slow clock is generated either by the slow clock crystal oscillator or by the slow clock rc oscillator. the selection between the rc or the cryst al oscillator is made by writing the xtalsel bit in the supply controller control register (supc_cr). 29.4.1 slow clock rc oscillator by default, the slow clock rc oscilla tor is enabled and selected. the user has to take into account the possible drifts of the rc oscillator. more deta ils are given in the section ?dc charac teristics? of the product datasheet. it can be disabled via the xtalsel bit in supc_cr. 29.4.2 slow clock crystal oscillator the clock generator integrates a 32768 hz low-power oscillator. to use th is oscillator, the xin32 and xout32 pins must be connected to a 32768 hz crystal. tw o external capacitors must be wired as shown in figure 29-2 . more details are given in the section ?dc characteristics? of the product datasheet. note that the user is not obliged to use the slow clock crysta l and can use the rc oscillator instead. figure 29-2. typical slow clock crystal oscillator connection the user can select the crystal oscillator to be the source of the slow clock, as it provides a more accurate frequency. the command is made by writing supc_cr with the xtalsel bit at 1. this results in a sequence which enables th e crystal oscillator and then disables the rc osc illator to save power. t he switch of the slow clock source is glitch free. the oscsel bit of the supply controller status register (supc_sr) or the oscsel bit of the pmc status register (pmc_sr) tracks the oscillator frequency downstr eam. it must be re ad in order to be informed when the switch sequence, initiated when a new value is written in the xtalsel bit of supc_cr, is done. coming back on the rc oscillator is only possible by shutti ng down the vddbu power su pply. if the user does not need the crystal oscillator, the xin32 and xout32 pins can be left unconnected. the user can also set the crystal oscillator in bypass m ode instead of connecting a crystal. in this case, the user has to provide the external clock signal on xin32. the i nput characteristics of the xin32 pin are given in the product electrical characteristics section. in order to set the bypass mode, the oscbypass bit of the supply controller mode register (supc_mr) needs to be set at 1. the user can set the slow clock crystal oscillator in bypass mode instead of co nnecting a crystal. in this case, the user has to provide the external cl ock signal on xin32. the input characte ristics of the xin32 pin under these conditions are given in the product electrical characteristics section. the programmer has to be sure to set the oscbypass bit in supc_m r and xtalsel bit in supc_cr. xin32 xout32 gnd 32768 hz crystal
559 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 29.5 main clock figure 29-3 shows the main clock block diagram. figure 29-3. main clock block diagram the main clock has two sources: ? 4/8/12 mhz fast rc oscillator which starts very quickly and is used at startup. ? 3 to 20 mhz crystal or ceramic resonator-ba sed oscillator which can be bypassed (refer to section 29.5.5 ?bypassing the main crystal oscillator? ). 29.5.1 fast rc oscillator after reset, the 4/8/12 mhz fast rc oscillator is enabled with the 4 mhz frequency selected and it is selected as the source of mainck. mainck is the defa ult clock selected to start the system. the fast rc oscillator frequencies are ca librated in production e xcept the lowest frequency which is not calibrated. refer to the ?dc characteristics? section of the product datasheet. xin xout moscxten moscxtst moscxts main clock frequency counter mainf slck slow clock 3-20 mhz crystal or ceramic resonator oscillator 3-20 mhz oscillator counter moscrcen fast rc oscillator moscrcs moscrcf moscrcen moscxten moscsel moscsel moscsels 1 0 mainck main clock mainck main clock ref. rcmeas ckgr_mcfr ckgr_mor ckgr_mor ckgr_mor pmc_sr pmc_sr ckgr_mor ckgr_mor ckgr_mor ckgr_mor ckgr_mor ckgr_mcfr pmc_sr ckgr_mcfr mainfrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 560 the software can disable or enable the 4/8/12 mhz fast rc oscillator wi th the moscrcen bit in the clock generator main oscillato r register (ckgr_mor). the user can also select the output fr equency of the fast rc oscillator, eith er 4/8/12 mhz are available. it can be done through moscrcf bits in ckgr_m or. when changing this frequency selection, the moscrcs bit in the power management controller status register (pmc_sr) is automatically cleared and mainck is stopped until the oscillator is stabilized. once the oscillator is stabilized, mainck restarts and moscrcs is set. when disabling the main clock by clearing the mos crcen bit in ckgr_mor, the moscrcs bit in pmc_sr is automatically cleared, indicating the main clock is off. setting the moscrcs bit in the power management contro ller interrupt enable register (pmc_ier) can trigger an interrupt to the processor. when main clock (mainck) is not used to drive the pr ocessor and frequency monitor (slck or pllack is used instead), it is recommended to disable the main oscillators. the cal4, cal8 and cal12 values in the pmc oscillator calibration register (pmc_o cr) are the default values set by atmel during production. these values are stored in a specific flash memory area different from the main memory plane. these values cannot be modified by the user and cannot be erased by a flash erase command or by the erase pin. values written by the user's application in pmc_ocr are reset after each power up or peripheral reset. 29.5.2 fast rc oscillator clock frequency adjustment it is possible for the user to adjust the main rc oscillator frequency throu gh pmc_ocr. by default, sel4/8/12 are low, so the rc oscillator will be driven with flash calibration bits which are programmed duri ng chip production. the user can adjust the trimming of th e 4/8/12 mhz fast rc oscillator through th is register in or der to obtain more accurate frequency (to compensate derating factors such as temperature and voltage). in order to calibrate the oscillator lower frequency, sel4 must be set to 1 and a good frequency value must be configured in cal4. likewise, sel8/12 must be set to 1 and a trim value must be configured in cal8/12 in order to adjust the other freque ncies of the oscillator. it is possible to adjust th e oscillator frequency while operating from this clock. fo r example, when running on lowest frequency it is possible to change th e cal4 value if sel4 is set in pmc_ocr. it is possible to restart, at anytime, a measurement of the main frequency by means of the rcmeas bit in main clock frequency register (ckgr_mcfr). thus, when mainfrdy flag reads 1, another read access on ckgr_mcfr provides an image of the frequency of the main clock on mainf field. the software can calculate the error with an expected frequency and correct the ca l4 (or cal8/cal12) field accordingly. this may be used to compensate frequency drift due to deratin g factors such as temperature and/or voltage. 29.5.3 3 to 20 mhz crystal or ceramic resonator-based oscillator after reset, the 3 to 20 mhz crystal or ceramic resonator-b ased oscillator is disabled a nd it is not selected as the source of mainck. the user can select the 3 to 20 mhz crystal or ceramic resonato r-based oscillator to be the source of mainck, as it provides a more accurate frequency. the softwa re enables or di sables the main oscilla tor in order to reduce power consumption by clearing th e moscxten bit in ckgr_mor. when disabling the main oscillator by clearing the moscxten bit in ckgr_mor, the moscxts bit in pmc_sr is automatically cleared, indicating the main clock is off. when enabling the main oscillator, the user must initiate the main oscillato r counter with a value corresponding to the start-up time of the o scillator. this start-up time depends on the crysta l frequency connect ed to the oscillator. when the moscxten bit and the moscxtst are written in ckgr_mor to enable the main oscillator, the xin and xout pins are automatica lly switched into oscillato r mode and moscxts bit in pmc_sr is cleared and the
561 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 counter starts counting down on the slow clock divided by 8 from the moscxtst value. since the moscxtst value is coded with 8 bits, the maxi mum start-up time is about 62 ms. when the counter reaches 0, the moscxts bit is set, i ndicating that the main clock is valid. setting the moscxts bit in the interrupt mask register (pmc _imr) can trigger an interrupt to the processor. 29.5.4 main clock oscillator selection the user can select the source of the main clock from ei ther the 4/8/12 mhz fast rc oscillator, the 3 to 20 mhz crystal oscillator or the cerami c resonator-based oscillator. the advantage of the 4/8/12 mhz fast rc oscillator is its fast start-up time. by default, this oscillator is selected to start the system and when entering wait mode. the advantage of the 3 to 20 mhz crystal oscillator or ceramic resonator-based oscillator is the high level of accuracy provided. the selection of the oscillator is m ade by writing the moscsel bit in ckgr_mor. the swit ch of the main clock source is glitch-free, so there is no need to run out of slck, pllack or pllbck in order to change the selection. the moscsels bit of pmc_sr indicates when the switch sequence is done. setting the moscsels bit in pmc_imr can trigger an interrupt to the processor. enabling the fast rc oscillator (moscrcen = 1) and changing the fast rc fr equency (mosccrf) at the same time is not allowed. the fast rc must be enabled first and its frequency changed in a second step. 29.5.5 bypassing the main crystal oscillator prior to bypassing the 3 to 20 mhz crystal oscillator, the external clock freq uency provided on the xin pin must be stable and within the values specified in the xin clock characteristics in the section ?electri cal characteristics?. the sequence is as follows: 1. make sure an external clock is connected on xin. 2. enable the bypass by writing a 1 to ckgr_mor.moscxtby. 3. disable the 3 to 20 mhz oscillator by writing a 0 to bit ckgr_mor.moscxten. 29.5.6 switching main clock between the main rc oscillator and fast crystal oscillator both sources must be enabled during the switchover operation. only after completion can the unused oscillator be disabled. if switching to fast crystal oscillator, the cl ock presence must first be checked according to what is described in section 29.5.7 ?software sequence to detect the presence of fast crystal? because the source may not be reliable (crystal failure or bypass on a non-existent clock). 29.5.7 software sequence to detect the presence of fast crystal the frequency meter carried on ckgr_mcfr is operating on the selected main clock a nd not on the fast crystal clock nor on the fast rc oscillator clock. therefore, to check for the presence of the fast crystal clock, it is necessary to have the main clock (mainck) driven by the fast crystal clock (moscsel=1). the following software sequence order must be followed: 1. mck must select the slow clock (css=0 in t he master clock register (pmc_mckr) register). 2. wait for the mckrdy flag in pmc_sr to be 1. 3. the fast crystal must be enabled by programming 1 in the moscxten field in the ckgr_mor register with the moscxtst field being programmed to the appropriate value (see the electrical characteristics chapter).
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 562 4. wait for the moscxts flag to be 1 in pmc_sr to get the end of a start-up period of the fast crystal oscillator. 5. then, moscsel must be pr ogrammed to 1 in ckgr_mor to select fa st main crystal osc illator for the main clock. 6. moscsel must be read until its value equals 1. 7. then the moscsels status flag must be checked in pmc_sr. at this point, two cases may occur (either moscsel s = 0 or moscsels = 1). ? if moscsels = 1: there is a valid crystal connected and its frequency can be determined by initiating a frequency measure by programming rcmeas in ckgr_mcfr. ? if moscsels = 0: ? there is no fast crystal clock (either no crystal co nnected or a crystal clock out of specification). a frequency measure can reinforce this status by initiating a frequency measure by programming rcmeas in ckgr_mcfr. ? if moscsels=0, the selection of the main clock must be programmed back to the main rc oscillator by writing moscsel to 0 prior to di sabling the fast crystal oscillator. ? if moscsels=0, the crystal oscillator c an be disabled (moscx ten=0 in ckgr_mor). 29.5.8 main clock frequency counter the device features a main clock frequency counter that provides the frequency of the main clock. the main clock frequency counter is reset and starts incrementing at the main clock speed after the next rising edge of the slow clock in the following cases: ? when the 4/8/12 mhz fast rc oscilla tor clock is selected as the sour ce of main clock and when this oscillator becomes stable (i.e ., when the moscrcs bit is set) ? when the 3 to 20 mhz crystal or ceramic resonator-based oscilla tor is selected as the source of main clock and when this oscillator becomes stable (i.e., when the moscxts bit is set) ? when the main clock oscilla tor selection is modified ? when the rcmeas bit of ckgr _mfcr is written to 1. then, at the 16th falling edge of slow clock, the mainfrdy bit in ckgr_mcfr) is set and the counter stops counting. its value can be read in the mainf field of ckgr_mcfr and gives the number of main clock cycles during 16 periods of slow cl ock, so that the freq uency of the 4/8/12 mhz fast rc o scillator or 3 to 20 mhz crystal or ceramic resonator- based oscillator ca n be determined.
563 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 29.6 divider and pll block the device features one divider/two pll block that permits a wide range of frequencies to be selected on either the master clock, the processor clo ck or the programmable clock outputs. figure 29-4 shows the block diagram of the dividers and pll blocks. figure 29-4. dividers and pll block diagram 29.6.1 divider and phase lock loop programming the divider can be set between 1 and 255 in steps of 1. when a divider field (div) is cleared, the output of the corresponding divider and the pll output is a continuous signal at level 0. on reset, each div field is cleared, thus the corresponding pll input clock is stuck at 0. the plls (plla, pllb) allow multiplicat ion of the slck clock source for plla or divided mainck or plla output clock for pllb. the pll clock signal has a frequency that depends on the respective source signal frequency and on the parameters div (, divb) and mul (mula, mulb) and pllen (pllaen). the factor applied to the source signal frequency is (mul + 1)/div. when mul is written to 0 or pllen=0, the pll is dis abled and its power consumption is saved. note that there is a delay of tw o slck clock cycles between the disable command and the real disable of the pll. re-enabling the pll can be performed by writing a value higher than 0 in the mul field and plla(b)en higher than 0. to change the frequency of the plla, the plla must be fi rst disabled by writing 0 in the mula field and 0 in pllacount field. then, wait for two slck clock cycl es before configuring the plla to generate the new divider b divb pll b mulb pll a counter pllbcount lockb pll a counter pllacount locka mula slck pllack pllbck pll b mainck pllbdiv2 srcb 0 1 slck plladiv2 ckgr_pllbr ckgr_pllar ckgr_pllar ckgr_pllbr ckgr_pllbr pmc_sr pmc_sr pmc_mckr pmc_mckr ckgr_pllbr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 564 frequency by programming a new multiplier in mula and the pllacount field in the same register access. see electrical characteristics to get the pllacount values covering the pll transient time. whenever the pll is re-enabled or on e of its parameters is changed, the lock (locka, lockb) bit in pmc_sr is automatically cleared. the valu es written in the pllcount field (pllacount, pllbcount) in ckgr_pllr (ckgr_pllar, ckgr_pllbr) are loaded in the pll coun ter. the pll counter then decrements at the speed of the slow clock until it reaches 0. at this time, the lock bit is set in pmc_sr and can trigger an interrupt to the processor. the user has to load the num ber of slow clock cycles required to cover the pll transient time into the pllcount field. the pll clock can be divided by 2 by writing th e plldiv2 (plladiv2, pllbdiv2) bit in pmc_mckr. the plladiv2 has no effect on pllb clock input because t he output of the plla is directly routed to pllb input selection. it is prohibited to change the 4/8/ 12 mhz fast rc oscillator or the main o scillator selection in ckgr_mor while the master clock source is the pll and the pl l reference clock is th e fast rc oscillator. the user must: 1. switch on the main rc oscillator by wr iting a 1 to the css field of pmc_mckr. 2. change the frequency (moscrcf) or osc illator selection (moscsel) in ckgr_mor. 3. wait for moscrcs (if frequency ch anges) or moscsels (if oscillato r selection changes) in pmc_sr. 4. disable and then enable the pll. 5. wait for the lock flag in pmc_sr. 6. switch back to the pll by writing the appr opriate value to the css field of pmc_mckr.
565 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30. power management controller (pmc) 30.1 description the power management controller (pmc) optimizes power consumption by controlling all system and user peripheral clocks. the pmc enables/disables the clock inputs to many of the peripherals and the cortex-m4 processor. the supply controller selects between the 32 khz rc oscillator or the slow cryst al oscillator. the unused oscillator is disabled automatically so that power consumption is optimized. by default, at startup, the chip runs out of the master cloc k using the fast rc oscillator running at 4 mhz. the user can trim the 8 and 12 mhz rc oscillator frequencies by software. 30.2 embedded characteristics the power management controller provides the following clocks: ? mck, the master clock, programmable from a few hun dred hz to the maximum operating frequency of the device. it is available to the modules running pe rmanently, such as the enhanced embedded flash controller. ? processor clock (hclk) and coprocessor (second processor) clock (cphclk), automatically switched off when entering the processor in sleep mode. ? free-running processor clock (fclk) and free-running coprocessor clock (cpfclk) ? one systick external clock for each cortex-m4 core ? peripheral clocks, provided to the embedded peripherals (usart, spi, twi, tc, etc.) an d independently controllable. ? programmable clock outputs (pckx), se lected from the clock generator out puts to drive the device pck pins. the power management controller also provides the following operations on clocks: ? a main crystal oscillato r clock failure detector. ? a 32768 hz crystal osc illator frequency monitor. ? a frequency counter on main cloc k and an on-the-fly adjustabl e main rc oscillator frequency.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 566 30.3 block diagram figure 30-1. general clock block diagram plla pllb and divider /2 plladiv2 pllbdiv2 management controller main clock mainck control status xin xout xin32 xout32 slck xtalsel (supply controller) 0 1 0 1 3-20 mhz crystal or ceramic resonator oscillator embedded 4/8/12 mhz fast rc oscillator 32768 hz crystal oscillator embedded 32 khz rc oscillator srcb 1 0 clock generator slow clock power periph_clk[n] int slck mainck pllack prescaler / 1,/2,/3,/4,/8, /16,/32,/64 processor clock controller sleep mode master clock controller (pmc_mckr) peripherals clock controller (pmc_pcerx / pmc_pcr) pllbck core 0 (cm4-p0 clock system) core 0 (cm4-p0 clock system) core 1 (cm4-p1 clock system) core 1 (cm4-p1 clock system) pres css on/off on/off on/off periph_clk[n+1] periph_clk[n+2] slck mainck pllack prescaler divide by 1 to 16 master clock controller (pmc_mckr) pllbck cppres cpcss on/off periph_clk[m+2] int coprocessor clock cphclk where m is an index for the coprocessor system peripherals cpfclk coprocessor free running clock coprocessor systick clock cpsystick divider / 8 divider / 8 mck pmc_scer/scdr cpck= on/off where n is an index for the processor system peripherals on/off periph_clk[m] coprocessor bus master clock cpbmck processor clock hclk fclk processor free running clock processor systick clock systick processor bus master clock mck pmc_scer/scdr cpbmck= on/off coprocessor clock controller sleep mode pllb clock pllbck plla clock pllack pmc_mckr pmc_mckr moscsel ckgr_mor ckgr_pllbr
567 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.4 master clock controller the master clock controller provides selection and divi sion of the master clock (m ck) and coprocessor master clock (cpmck). mck is the clock pr ovided to all the peripherals in the sub-system 0 and cpmck is the clock provided to all peripherals in the sub-system 1. the master clock is select ed from one of the clocks provided by the clock generator. selecting the slow clock provides a slow clock signal to the whole device. selecting the main clock saves power consumption of the plls. the master clock controller is made up of a clock selector and a prescaler. the master clock selection is made by writing the css/ cpcss field (clock source selection/coprocessor clock source selection) in pmc_mc kr. the prescaler supports the division by a power of 2 of the selected clock between 1 and 64, and the division by 3. the pres/cppres field in pmc_mckr programs the prescaler. each time pmc_mckr is written to de fine a new master clock, the mckrdy bit is cleared in pmc_sr. it reads 0 until the master clock is established. then, the mckrdy bit is set and can trigger an interrupt to the processor. this feature is useful when switching from a high-speed clock to a lower one to inform the software when the change is actually done. figure 30-2. master clock controller 30.5 processor clock controller the pmc features a processor clock controller (hclk) and a coprocessor clock controller (cphclk) that implements the processor sleep mode. these processo r clocks can be disabled by executing the wfi (waitforinterrupt) or the wfe (waitforevent) processor instruction while the lpm bit is at 0 in the pmc fast startup mode register (pmc_fsmr). the processor clock controller hclk is enabled after a reset and is automatically re-enabled by any enabled interrupt. the coprocessor clock controller cphclk is disabled after reset. it is up to the master application to enable the cphclk. similar to hclk, cphclk is automa tically re-enabled by any enabled instruction after having executed a wfi instruction. the processor sleep mode is entered by disabling the processor clock, which is automatically re-enabled by any enabled fast or normal interrupt, or by the reset of the product. when processor sleep mode is entered, the current instruction is finish ed before the clock is stopped, but this does not prevent data transfers from other masters of the system bus. 30.6 systick clock the systick calibration value is fixed to 8000 which allows the generation of a time base of 1 ms with systick clock to the maximum frequency on mck divided by 8. 30.7 peripheral clock controller the power management controller cont rols the clocks of each embedded peri pheral by means of the peripheral clock controller. the user can individually en able and disable the clock on the peripherals. slck master clock prescaler to the mck divider pres css mainck pllack pllbck to the processor clock controller (pck) pmc_mckr pmc_mckr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 568 the user can also enable and disable these clocks by writing peripheral clock enable 0 (pmc_pcer0), peripheral clock disable 0 (pmc_pcdr0), peripheral clock enable 1 (pmc_pcer1) and peripheral clock disable 1 (pmc_pcdr1) registers. the stat us of the peripheral clock activity can be read in the peripheral clock status register (pmc_pcsr0) and peripher al clock status register (pmc_pcsr1). if the peripherals located on the coprocessor system bus require data exchange with the co-processor or the main processor, the cpbmck clock must be enabled pr ior to enable any co-pro cessor peripheral clock. when a peripheral clock is disabled, the clock is immediately stopped. the peripheral clocks are automatically disabled after a reset. to stop a peripheral, it is recomm ended that the system software wait unti l the peripheral has executed its last programmed operation before disabling the clock. this is to avoid data corruption or erroneous behavior of the system. the bit number within the peripheral clock cont rol registers (pmc_pcer0-1, pmc_pcdr0-1, and pmc_pcsr0-1) is the peripheral identifier defined at the product level. the bit number corresponds to the interrupt source number assigned to the peripheral. 30.8 free-running processor clock the free-running processor clock (fclk) together with the free-running coprocessor master clock (cpfclk) used for sampling interrupts and clocking debug blocks ensures that interrupts can be sampled, and sleep events can be traced, while the processor(s) is(are) sleeping. it is co nnected to master clock (mck )/coprocessor master clock (cpmck). 30.9 programmable clock output controller the pmc controls three signals to be output on ex ternal pins, pckx. ea ch signal can be independently programmed via the programmable clock registers (pmc_pckx). pckx can be independently selected between the slow clo ck (slck), the main clock (mainck), the plla clock (pllack), the pllb clock (pllbck),and the master clock (mck) by writ ing the css field in pmc_pckx. each output signal can also be divided by a power of 2 between 1 and 64 by writing the pres (prescaler) field in pmc_pckx. each output signal can be enabled and disabled by writing 1 in the corresponding bit, pckx of pmc_scer and pmc_scdr, respectively. status of the active programmable output cloc ks are given in the pckx bits of pmc_scsr. pckrdyx status flag in pmc_sr indicates that the pr ogrammable clock is actually what has been programmed in the programmable clock registers. as the programmable clock controller does not manage with glitch prevention when switch ing clocks, it is strongly recommended to disable the programmable clock before any configuration change and to re-enable it after the change is actually performed. 30.10 main processor fast startup at exit from wait mode, the device allo ws the main processor to restart in less than 10 microseconds only if the c- code function that manages the wait mode entry and exit is linked to and executed from on-chip sram. the fast startup time cannot be achiev ed if the first instruction after an ex it is located in the embedded flash. if fast startup is not required, or if the first instruction after a wait mode exit is located in embedded flash, see section 30.11 ?main processor startup from embedded flash? . prior to instructing the de vice to enter wait mode:
569 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1. select the fast rc oscillator as the master clock so urce (the css field in pmc_ mckr must be written to 1). 2. disable the pll if enabled. 3. clear the internal wake-up sources. the system enters wait mo de either by setting the waitmode bit in ckgr_mor, or by executing the waitforevent (wfe) instruction of the processor while the lpm bit is at 1 in pmc_fsmr. immediately after setting the waitmode bit or using the wfe instruction, wait for the mckrdy bit to be set in pmc_sr. in case of dual core activity, it is recommended to check the coprocessor state before instructing the main processor to enter wait mode. a fast startup is enabled upon the detection of a program med level on one of the 16 wake-up inputs (wkup) or upon an active alarm from the rtc and rtt. the polarity of the 16 wake-up inputs is programmable by writing the pmc fast startup polarity register (pmc_fspr). the fast startup circuitry, as shown in figure 30-3 , is fully asynchronous and provides a fast startup signal to the power management controller. as soon as the fast star tup signal is asserted, the embedded 4/8/12 mhz fast rc oscillator restarts automatically. when entering wait mode, the embedded flash can be pl aced in one of the low-power modes (deep-power- down or standby modes) depending on the configuration of the flpm field in the pmc_fsmr. the flpm field can be programmed at anytime and its value will be applied to the next wait mode period. the power consumption reduction is optimal when configuring 1 (deep-power-down mode) in field flpm. if 0 is programmed (standby mode), the pow er consumption is slightly highe r than in deep-power-down mode. when programming 2 in field flpm, the wait mode flash pow er consumption is equival ent to that of the active mode when there is no read access on the flash. figure 30-3. fast startup circuitry each wake-up input pin and alarm can be enabled to gener ate a fast startup event by setting the corresponding bit in pmc_fsmr. fast_restart wkup15 fstt15 fstp15 wkup1 fstt1 fstp1 wkup0 fstt0 fstp0 rttal rtcal rtt alarm rtc alarm
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 570 the user interface does not provide any status for fast startup, but the user can easily recover this information by reading the pio controller and the st atus registers of the rtc and rtt. 30.11 main processor star tup from embedded flash the inherent start-up time of the embedded flas h cannot provide a fast startup of the system. if system fast start-up time is not required, the first in struction after a wait mode exit can be located in the embedded flash. under these c onditions, prior to entering wait mode, the flash controller must be programmed to perform access in 0 wait-state (see flash controller section). the procedure and conditions to enter wait mode and the circ uitry to exit wait mode ar e strictly the same as fast startup (see section 30.10 ?main processor fast startup? ). 30.12 coprocessor sleep mode the coprocessor enters sleep mode by executing the waitfo rinterrupt (wfi) instruction of the coprocessor. any enabled interrupt can wake the processor up. 30.13 main clock failure detector the clock failure detector monitors the main crystal oscillator or ceramic resonator-based oscillator to identify an eventual failure of this oscillator. the clock failure detector can be enabled or disabled by bit cfden in ckgr_mor . after a vddcore reset, the detector is disabled. however, if the oscillator is disabled (moscx ten = 0), the detector is disabled too. a failure is detected by means of a counter incrementing on the main oscillator clock edge and timing logic clocked on the slow rc oscillator contro lling the counter. thus, the slow rc oscillator must be enabled. the counter is cleared when the slow rc oscillator clock signal is low and enabled when the si gnal is high. thus the failure detection time is 1 slow rc oscillator cloc k period. if, during the high level period of the slow rc oscillator clock signal, less th an 8 fast crystal osc illator clock periods have been count ed, then a failu re is reported. if a failure of the main oscillator is detected, bit cfdev in pmc_sr indi cates a failure event and generates an interrupt if the corresponding interrupt source is enable d. the interrupt remains acti ve until a read occurs in pmc_sr. the user can know the status of the clock failure detection at any time by reading the cfds bit in pmc_sr. figure 30-4. clock failure detection (example) if the main oscillator is selected as the source clock of mainck (moscsel in ckgr_m or = 1), and if the master clock source is pllackor pllbck (c ss = 2), a clock failure detection aut omatically forces mainck to be the source clock for the master clock (mck).then, regardles s of the pmc configuration, a clock failure detection main crytal clock slck note: ratio of clock periods is for illustration purposes only cdfev cdfs read pmc_sr
571 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 automatically forces the fast rc oscillator to be the sour ce clock for mainck. if the fast rc oscillator is disabled when a clock failure detection occurs, it is automatica lly re-enabled by the clock failure detection mechanism. it takes 2 slow rc oscillator clock cycles to detect and switch from the main oscillator, to the fast rc oscillator if the source master clock (mck) is main clock (mainck), or three slow clock rc oscillator cycles if the source of mck is pllack or pllbck. the user can know the status of the clock failure detector at any time by reading the fos bit in pmc_sr. this fault output remains active until th e defect is detected and until it is clea red by the bit foclr in the pmc fault output clear register (pmc_focr). 30.14 slow crystal clo ck frequency monitor the frequency of the slow clock crysta l oscillator can be monitored by m eans of logic driven by the main rc oscillator known as a reliable clock source. this f unction is enabled by configuring the xt32kfme bit of ckgr_mor. the sel4/sel8/sel12 bits of pmc_ocr must be cleared. an error flag (xt32kerr in pmc_sr) is asserted when the slow clock crystal oscillator frequency is out of the +/- 10% nominal frequency value (i.e. 32768 hz). the error flag can be cleared only if the slow clock frequency monitoring is disabled. the monitored clock frequency is declared invalid if at l east 4 consecutive clock period measurement results are over the nominal period +/-10%. due to the possible frequency variation of the embedded main rc oscillator acting as reference clock for the monitor logic, any slow clock crystal frequency deviation over +/-10% of the nominal frequency is systematically reported as an error by means of xt32kerr in pmc_sr. between -1% and -10% and +1% and +10%, the error is not systemati cally reported. thus only a crystal running at 32768 hz frequency ensures th at the error flag will not be asserted. the permitted drift of the crystal is 10000ppm (1%), which allows any standard crystal to be used. if the main rc frequency needs to be changed while the slow clock frequency monitor is operating, the monitoring must be stopped prior to change the main rc frequen cy. then it can be re-enabled as soon as moscrcs is set in pmc_sr. the error flag can be defined as an interrupt source of the pmc by setting the xt32kerr bit of pmc_ier. 30.15 programming sequence 1. if the fast crystal oscillator is not required, the pll and divider can be directly configured ( step 6. ) else the fast crystal oscillator must be started ( step 2. ). 2. enable the fast crystal oscillator: the fast crystal oscillator is enab led by setting the moscxten field in ckgr_mor. the user can define a start-up time. this can be achieved by writing a valu e in the moscxtst field in ckgr_mor. once this register has been correctly configured, the user must wait for moscxts field in pmc_sr to be set. this can be done either by polling moscxt s in pmc_sr, or by wait ing for the interrupt line to be raised if the associated interrupt source (moscxt s) has been enabled in pmc_ier. 3. switch the mainck to the main crystal oscillator by setting moscsel in ckgr_mor. 4. wait for the moscsels to be set in pmc_sr to ensure the switchover is complete. 5. check the main clock frequency: this main clock frequency can be measured via ckgr_mcfr. when the main rc oscillator frequency is 4 mhz, the accuracy of the meas urement is +/-40% as this frequency is not trimmed during production. ther efore, +/-10% accuracy is obtained only if the rc oscillator frequency is configured for 8 or 12 mhz.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 572 read ckgr_mcfr until the mainfrdy field is set, after which the user can read the mainf field in ckgr_mcfr by performing an additional read. this pr ovides the number of main clock cycles that have been counted during a period of 16 slow clock cycles. if mainf = 0, switch the mainck to the fast rc os cillator by clearing moscsel in ckgr_mor. if mainf 0, proceed to step 6. 6. set pllx and divider (if not required, proceed to step 7. ): in the names pllx, divx, mulx, lockx, pllxcount, and ckgr_pllxr, ?x? represents a or b. all parameters needed to configure pllx and the divider are located in ckgr_pllxr. the divx field is used to contro l the divider itself. this parameter can be programmed between 0 and 127. divider output is divider input divided by divx parameter . by default, divx field is cleared which means that the divider and pllx are turned off. the mulx field is the pllx multiplier factor. this parameter can be programmed between 0 and 254. if mulx is cleared, pllx will be turned off, otherwise the pllx output fr equency is pllx input frequency multiplied by (mulx + 1). the pllxcount field specifies the numb er of slow clock cycles before the lockx bit is set in the pmc_sr after ckgr_pllxr has been written. once ckgr_pllxr has been written, the user must wait for the lockx bit to be set in the pmc_sr. this can be done either by polling lockx in pmc_sr or by waiting for the in terrupt line to be raised if the associated interrupt source (lockx) has been enabled in pmc_ier. all fields in ckgr_pllxr can be programmed in a single write operation. if at some st age one of the following parameters, mulx or divx is modified, the lockx bit goes low to indicate that pllx is not yet ready. when pllx is locked, lockx is set again. the user must wait for the lockx bit to be set before using the pllx output clock. 7. select the master clock and processor clock the master clock and the processor clock are configurable via pmc_mckr. the css field is used to select the clock source of th e master clock and processor clock dividers. by default, the selected clock source is the main clock. the pres field is used to define the processor cloc k and master clock prescaler. the user can choose between different values (1, 2, 3, 4, 8, 16, 32, 64). prescaler output is the selected clock source frequency divided by the pres value. once the pmc_mckr has been written, the user must wait for the mckrdy bit to be set in the pmc_sr. this can be done either by polling mckrdy in pmc_sr or by waiting for the interrupt line to be raised if the associated interrupt source (mckrdy) has been en abled in pmc_ier. pm c_mckr must not be programmed in a single write operation. the pr ogramming sequence for pmc_mckr is as follows: ? if a new value for css field corresponds to pll clock, ? program the pres field in pmc_mckr. ? wait for the mckrdy bit to be set in pmc_sr. ? program the css field in pmc_mckr. ? wait for the mckrdy bit to be set in pmc_sr. ? if a new value for css field correspon ds to main clock or slow clock, ? program the css field in pmc_mckr. ? wait for the mckrdy bit to be set in the pmc_sr. ? program the pres field in pmc_mckr. ? wait for the mckrdy bit to be set in pmc_sr.
573 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 if at some stage, parameters css or pres are modi fied, the mckrdy bit goes low to indicate that the master clock and the processor clock are not yet ready. the user must wait for mckrdy bit to be set again before using the master and processor clocks. note: if pllx clock was selected as the master clock and the user decides to mo dify it by writing in ckgr_pllxr, the mckrdy flag will go low while pllx is unlocked. once pllx is locked again, lockx goes high and mckrdy is set. while pllx is unlocked, the master clock selection is auto matically changed to slow clock for plla and main clock for pllb. for further information, see section 30.16.2 ?clock switching waveforms? . code example: write_register(pmc_mckr,0x00000001) wait (mckrdy=1) write_register(pmc_mckr,0x00000011) wait (mckrdy=1) the master clock is main clock divided by 2. 8. select the programmable clocks programmable clocks are controlled via regi sters, pmc_scer, pmc_ scdr and pmc_scsr. programmable clocks can be enabled and/or di sabled via pmc_scer and pmc_scdr. three programmable clocks can be used. pmc_scsr indicate s which programmable clock is enabled. by default all programmable clocks are disabled. pmc_pckx registers are used to configure programmable clocks. the css field is used to select the programmable clo ck divider source. several clock options are available: main clock, slow clock, master clock, pllack, pl lbck. the slow clock is the default cl ock source. the pres field is used to control the programmable clock prescaler. it is possible to choose between different values (1, 2, 4, 8, 16, 32, 64). programmab le clock output is prescaler input divided by pres parameter. by default, the pres value is cleared which means that pckx is equal to slow clock. once pmc_pckx register has been configured, the corresponding programmable clock must be enabled and the user is constrained to wait for the pckrdyx bi t to be set in the pmc_sr. this can be done either by polling pckrdyx in pmc_sr or by wait ing for the interrupt line to be ra ised if the associated interrupt source (pckrdyx) has been enabled in pmc_ier. all parameters in pmc_pckx can be programmed in a single write operation. if the css and pres parameters are to be modi fied, the corresponding programmable clock must be disabled first. the parameters can then be modified. once this has been done, the user must re-enable the programmable clock and wait for the pckrdyx bit to be set. 9. enable the peripheral clocks once all of the previous steps have been completed, th e peripheral clocks can be enabled and/or disabled via registers pmc_pcer0, pmc_ pcer, pmc_pcdr0 and pmc_pcdr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 574 30.16 clock switching details 30.16.1 master clock switching timings table 30-1 and give the worst case timings required for the master clock to switch from one selected clock to another one. this is in the ev ent that the prescaler is de- activated. when the prescaler is activated, an additional time of 64 clock cycles of the newly selected clock has to be added. notes: 1. pll designates either the plla or the pllb clock. 2. pllcount designates eitherpllacount or pllbcount. table 30-1. clock switching timings (worst case) from main clock slck pll clock to main clock ? 4 x slck + 2.5 x main clock 3 x pll clock + 4 x slck + 1 x main clock slck 0.5 x main clock + 4.5 x slck ? 3 x pll clock + 5 x slck pll clock 0.5 x main clock + 4 x slck + pllcount x slck + 2.5 x pllx clock 2.5 x pll clock + 5 x slck + pllcount x slck 2.5 x pll clock + 4 x slck + pllcount x slck table 30-2. clock switching timings between two plls (worst case) fro m plla clock pllb clock to plla clock 2.5 x plla clock + 4 x slck + pllacount x slck 3 x plla clock + 4 x slck + 1.5 x plla clock pllb clock 3 x pllb clock + 4 x slck + 1.5 x pllb clock 2.5 x pllb clock + 4 x slck+ pllbcount x slck
575 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.16.2 clock switching waveforms figure 30-5. switch master clock from slow clock to pllx clock figure 30-6. switch master clock from main clock to slow clock slow clock lock mckrdy master clock write pmc_mckr pllx clock slow clock main clock mckrdy master clock write pmc_mckr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 576 figure 30-7. change pllx programming figure 30-8. programmable clock output programming slow clock slow clock pllx clock lockx mckrdy master clock write ckgr_pllxr pllx clock pckrdy pckx output write pmc_pckx write pmc_scer write pmc_scdr pckx is disabled pckx is enabled pll clock is selected
577 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.17 register write protection to prevent any single software error from corrupting pm c behavior, certain registers in the address space can be write-protected by settin g the wpen bit in the pmc write protection mode register (pmc_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the pmc write protection status register (pmc_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading the pmc_wpsr. the following registers can be write-protected: ? pmc system clock enable register ? pmc system clock disable register ? pmc peripheral clock enable register 0 ? pmc peripheral clock disable register 0 ? pmc clock generator main oscillator register ? pmc clock generato r plla register ? pmc clock generato r pllb register ? pmc master clock register ? pmc programmable clock register ? pmc fast startup mode register ? pmc fast startup polarity register ? pmc coprocessor fast startup mode register ? pmc peripheral clock enable register 1 ? pmc peripheral clock disable register 1 ? pmc oscillator calibration register
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 578 30.18 power management controll er (pmc) user interface table 30-3. register mapping offset register name access reset 0x0000 system clock enable register pmc_scer write-only ? 0x0004 system clock disable register pmc_scdr write-only ? 0x0008 system clock status register pmc_scsr read-only 0x0000_0001 0x000c reserved ? ? ? 0x0010 peripheral clock enable r egister 0 pmc_pcer0 write-only ? 0x0014 peripheral clock disable register 0 pmc_pcdr0 write-only ? 0x0018 peripheral clock status regi ster 0 pmc_pcsr0 read-only 0x0000_0000 0x0020 main oscillator register ckgr_mor read/write 0x0000_0008 0x0024 main clock frequency register ckgr_mcfr read/write 0x0000_0000 0x0028 plla register ckgr_pllar read/write 0x0000_3f00 0x002c pllb register ckgr_pllbr read/write 0x0000_3f00 0x0030 master clock register pmc_mckr read/write 0x0000_0001 0x0034?0x003c reserved ? ? ? 0x0040 programmable clock 0 register pmc_pck0 read/write 0x0000_0000 0x0044 programmable clock 1 register pmc_pck1 read/write 0x0000_0000 0x0048 programmable clock 2 register pmc_pck2 read/write 0x0000_0000 0x004c? 0x005c reserved ? ? ? 0x0060 interrupt enable register pmc_ier write-only ? 0x0064 interrupt disable register pmc_idr write-only ? 0x0068 status register pmc_sr read-only 0x0003_0008 0x006c interrupt mask register pmc_imr read-only 0x0000_0000 0x0070 fast startup mode register pmc_fsmr read/write 0x0000_0000 0x0074 fast startup polarity register pmc_fspr read/write 0x0000_0000 0x0078 fault output clear register pmc_focr write-only ? 0x007c coprocessor fast startup mode register pmc_cpfsmr read/write 0x0000_0000 0x0080?0x00e0 reserved ? ? ? 0x00e4 write protection mode register pmc_wpmr read/write 0x0 0x00e8 write protection status register pmc_wpsr read-only 0x0 0x00ec?0x00fc reserved ? ? ? 0x0100 peripheral clock enable r egister 1 pmc_pcer1 write-only ? 0x0104 peripheral clock disable register 1 pmc_pcdr1 write-only ? 0x0108 peripheral clock status regi ster 1 pmc_pcsr1 read-only 0x0000_0000 0x010c reserved ? ? ?
579 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 note: if an offset is not listed in the table it must be considered as ?reserved?. 0x0110 oscillator calibration regi ster pmc_ocr read/write 0x0040_4040 0x114?0x120 reserved ? ? ? 0134?0x144 reserved ? ? ? table 30-3. register mapping (continued) offset register name access reset
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 580 30.18.1 pmc system clock enable register name: pmc_scer address: 0x400e0400 access: write-only this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? pckx: programmable clock x output enable 0: no effect. 1: enables the corresponding programmable clock output. ? cpck: coprocessor (second processor) clocks enable 0: no effect. 1: enables the corresponding coprocessor clocks (cphclk, cpsystick) if cpkey = 0xa ? cpbmck: coprocessor bus master clocks enable 0: no effect. 1: enables the corresponding coprocessor bus mast er clock (cpbmck,cpfclk) if cpkey = 0xa note: enabling cpbmck must be performed prior or at the same time as cpck is programmed to 1 in pmc_scer register or prior communication with one the peripher als of the coprocessor system bus. ? cpkey: coprocessor clocks enable key 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 cpkey ? ? cpbmck cpck 15 14 13 12 11 10 9 8 ?????p c k 2p c k 1p c k 0 76543210 ???????? value name description 0xa passwd this field must be written to 0xa in order to validate cpck field.
581 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.2 pmc system cl ock disable register name: pmc_scdr address: 0x400e0404 access: write-only this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? pckx: programmable clock x output disable 0: no effect. 1: disables the corresponding programmable clock output. ? cpck: coprocessor clocks disable 0: no effect. 1: enables the corresponding coprocessor clocks (cphclk, cpfclk, cpsystick) if cpkey = 0xa. ? cpbmck: coprocessor bus master clocks disable 0: no effect. 1: disables the corres ponding coprocessor bus master cl ock (cpbmck, cpfclk) if cpkey = 0xa note: disabling cpbmck must not be performed if cpck is 1 in pmc_scsr register. ? cpkey: coprocessor clocks disable key 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 cpkey ? ? cpbmck cpck 15 14 13 12 11 10 9 8 ?????p c k 2p c k 1p c k 0 76543210 ???????? value name description 0xa passwd this field must be written to 0xa in order to validate cpck field.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 582 30.18.3 pmc system clock status register name: pmc_scsr address: 0x400e0408 access: read-only ? pckx: programmable clock x output status 0: the corresponding programmable clock output is disabled. 1: the corresponding programmable clock output is enabled. ? cpck: coprocessor (second processor) clocks status 0: coprocessor clocks (cp hclk, cpsystick) are disabl ed (value after reset). 1: coprocessor clocks (cphcl k, cpsystick) are enabled. ? cpbmck: coprocessor bus master clock status 0: coprocessor clocks (cpbmck, cpfclk) are disabled (value after reset). 1: coprocessor clocks (cpbmck, cpfclk) are enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ??????c p b m c kc p c k 15 14 13 12 11 10 9 8 ?????p c k 2p c k 1p c k 0 76543210 ????????
583 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.4 pmc peripheral clock enable register 0 name: pmc_pcer0 address: 0x400e0410 access: write-only this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? pidx: peripheral clock x enable 0: no effect. 1: enables the corresponding peripheral clock. note: pidx refers to identifiers defined in the section ?periphe ral identifiers?. other peripherals can be enabled in pmc_pcer1 (section 30.18.23 ?pmc peripheral clock enable register 1? ). note: programming the control bits of the peripheral id that are not implemented has no effe ct on the behavior of the pmc. 31 30 29 28 27 26 25 24 pid31 ? pid29 pid28 pi d27pid26pid25pid24 23 22 21 20 19 18 17 16 pid23 pid22 pid21 pid20 pid19 pid18 pid17 pid16 15 14 13 12 11 10 9 8 pid15 pid14 pid13 pid12 pid11 pid10 pid9 pid8 76543210 ????????
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 584 30.18.5 pmc peripheral clock disable register 0 name: pmc_pcdr0 address: 0x400e0414 access: write-only this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? pidx: peripheral clock x disable 0: no effect. 1: disables the corresponding peripheral clock. note: pidx refers to identifiers defined in the section ?periphe ral identifiers?. other peripherals can be disabled in pmc_pcdr1 ( section 30.18.24 ?pmc peripheral clock disable register 1? ). 31 30 29 28 27 26 25 24 pid31 ? pid29 pid28 pi d27pid26pid25pid24 23 22 21 20 19 18 17 16 pid23 pid22 pid21 pid20 pid19 pid18 pid17 pid16 15 14 13 12 11 10 9 8 pid15 pid14 pid13 pid12 pid11 pid10 pid9 pid8 76543210 ????????
585 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.6 pmc peripheral clock status register 0 name: pmc_pcsr0 address: 0x400e0418 access: read-only ? pidx: peripheral clock x status 0: the corresponding peripheral clock is disabled. 1: the corresponding peripheral clock is enabled. note: pidx refers to identifiers defined in the section ?peripheral identifiers?. other peripherals status can be read in pmc_pc sr1 ( section 30.18.25 ?pmc peripheral clock status register 1? ). 31 30 29 28 27 26 25 24 pid31 ? pid29 pid28 pi d27pid26pid25pid24 23 22 21 20 19 18 17 16 pid23 pid22 pid21 pid20 pid19 pid18 pid17 pid16 15 14 13 12 11 10 9 8 pid15 pid14 pid13 pid12 pid11 pid10 pid9 pid8 76543210 ????????
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 586 30.18.7 pmc clock generator main oscillator register name: ckgr_mor address: 0x400e0420 access: read/write this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? moscxten: main crystal oscillator enable a crystal must be connect ed between xin and xout. 0: the main crystal oscillator is disabled. 1: the main crystal oscillator is enabled. moscxtby must be set to 0. when moscxten is set, the moscxts flag is set once the main crystal oscillator start-up time is achieved. ? moscxtby: main crystal oscillator bypass 0: no effect. 1: the main crystal oscillator is bypass ed. moscxten must be set to 0. an ex ternal clock must be connected on xin. when moscxtby is set, the moscxts fl ag in pmc_sr is automatically set. clearing moscxten and moscxtby bi ts resets the moscxts flag. note: when the main crystal oscillator bypass is disabled (mo scxtby=0), the moscxts flag must be read at 0 in pmc_sr before enabling the main crystal oscillator (moscxten=1). ? waitmode: wait mode command (write-only) 0: no effect. 1: puts the device in wait mode. ? moscrcen: main on-chi p rc oscillator enable 0: the main on-chip rc oscillator is disabled. 1: the main on-chip rc oscillator is enabled. when moscrcen is set, the moscrcs flag is set once the main on-chip rc oscillator start-up time is achieved. ? moscrcf: main on-chip rc oscillator frequency selection 31 30 29 28 27 26 25 24 ?????x t 3 2 k f m ec f d e nm o s c s e l 23 22 21 20 19 18 17 16 key 15 14 13 12 11 10 9 8 moscxtst 76543210 ? moscrcf moscrcen waitmode moscxtby moscxten
587 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 at startup, the main on-chip rc oscillator frequency is 4 mhz. note: moscrcf must be changed only if moscrcs is set in th e pmc_sr register. therefore moscrcf and moscrcen cannot be changed at the same time. ? moscxtst: main crystal oscillator start-up time specifies the number of slow clock cycles multiplied by 8 for the main crystal oscillator start-up time. ? key: write access password ? moscsel: main oscillator selection 0: the main on-chip rc oscillator is selected. 1: the main crystal os cillator is selected. ? cfden: clock failure detector enable 0: the clock failure detector is disabled. 1: the clock failure detector is enabled. note: 1. the slow rc oscillator must be enabled when the cfden is enabled. ? xt32kfme: slow crystal oscillator frequency monitoring enable 0: the 32768 hz crystal oscillator frequency monitori ng is disabled. 1: the 32768 hz crystal oscillator frequency monitori ng is enabled. value name description 0x0 4_mhz the fast rc oscillator frequency is at 4 mhz (default) 0x1 8_mhz the fast rc oscillator frequency is at 8 mhz 0x2 12_mhz the fast rc oscillator frequency is at 12 mhz value name description 0x37 passwd writing any other value in this field aborts the write operation. always reads as 0.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 588 30.18.8 pmc clock generator ma in clock frequency register name: ckgr_mcfr address: 0x400e0424 access: read/write this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? mainf: main clock frequency gives the number of main clock cycles within 16 slow clo ck periods in order to determine the main clock frequency: where frequency is in mhz. ? mainfrdy: main clock frequency measure ready 0: mainf value is not valid or the main oscillator is disabled or a measure has just been st arted by means of rcmeas. 1: the main oscillator has been enabled pr eviously and mainf value is available. note: to ensure that a correct value is read on the mainf field, the mainfrdy flag must be read at 1 then another read access mu st be performed on the register to ge t a stable value on the mainf field. ? rcmeas: rc oscillator frequency measure (write-only) 0: no effect. 1: restarts measuring of the main rc frequency. mainf will carry the new frequency as soon as a low to high transition occurs on the mainfrdy flag. the measure is performed on the main frequency (i.e. not limited to rc osc illator only), but if the main clock frequency source is the fast crystal oscillator, t he restart of measuring is not needed bec ause of the well known stability of crystal oscillators. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???r c m e a s???m a i n f r d y 15 14 13 12 11 10 9 8 mainf 76543210 mainf f mck mainf f slck () 16 ? =
589 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.9 pmc clock generator plla register name: ckgr_pllar address: 0x400e0428 access: read/write possible limitations on plla input frequencies and multiplier factors should be checked before using the pmc. this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? pllaen: plla control 0: plla is disabled. 1: plla is enabled 2 up to 255 = forbidden. ? pllacount: plla counter specifies the number of slow clock cycles before the lo cka bit is set in pmc_sr after ckgr_pllar is written. ? mula: plla multiplier 0: the plla is deactivated (pll a also disabled if diva = 0). 200 up to 254 = the plla clock frequency is the plla input frequency multiplied by mula + 1. unlisted values are forbidden. to change the plla frequency, please read section 29.6.1 ?divider and phase lock loop programming? . 31 30 29 28 27 26 25 24 ????? m u l a 23 22 21 20 19 18 17 16 mula 15 14 13 12 11 10 9 8 ? ? pllacount 76543210 pllaen
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 590 30.18.10pmc clock generator pllb register name: ckgr_pllbr address: 0x400e042c access: read/write possible limitations on pllb input frequencies and multiplier factors should be checked before using the pmc. this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? divb: pllb front-end divider 0: divider output is stuck at 0 and pllb is disabled. 1: divider is bypassed (divide by 1) 2 up to 255 = clock is divided by divb ? pllbcount: pllb counter specifies the number of slow clock cycles before the lo ckb bit is set in pmc_sr after ckgr_pllbr is written. ? mulb: pllb multiplier 0: the pllb is deactivated (pll b also disabled if divb = 0). 1 up to 62: the pllb clock frequency is the pllb input frequency multiplied by mulb + 1. unlisted values are forbidden. ? srcb: source for pllb 31 30 29 28 27 26 25 24 ??s r c b?? m u l b 23 22 21 20 19 18 17 16 mulb 15 14 13 12 11 10 9 8 ? ? pllbcount 76543210 divb value name description 0 mainck_in_pllb the pllb input clock is main clock 1 plla_in_pllb the pllb input clock is plla output
591 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.11pmc master clock register name: pmc_mckr address: 0x400e0430 access: read/write this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? css: master clock source selection ? pres: processor clock prescaler ? plladiv2: plla divisor by 2 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 cppres ? cpcss 15 14 13 12 11 10 9 8 ??p l l b d i v 2p l l a d i v 2???? 76543210 ?p r e s? ?c s s value name description 0 slow_clk slow clock is selected 1 main_clk main clock is selected 2 plla_clk plla clock is selected 3 pllb_clk pllbclock is selected value name description 0 clk_1 selected clock 1 clk_2 selected clock divided by 2 2 clk_4 selected clock divided by 4 3 clk_8 selected clock divided by 8 4 clk_16 selected clock divided by 16 5 clk_32 selected clock divided by 32 6 clk_64 selected clock divided by 64 7 clk_3 selected clock divided by 3 plladiv2 plla clock division 0 plla clock frequency is divided by 1. 1 plla clock frequency is divided by 2.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 592 ? pllbdiv2 pllb divisor by 2 ? cpcss: coprocessor master clock source selection ? cppres: coprocessor programmable clock prescaler 0 up to 15 = the selected clock is divided by cppres+1. pllbdiv2 pllb clock division 0 pllb clock frequency is divided by 1. 1 pllb clock frequency is divided by 2. value name description 0 slow_clk slow clock is selected 1 main_clk main clock is selected 2 plla_clk plla clock is selected 3 pllb_clk pllb clock is selected 4m c k m a s t e r c l o ck is selected
593 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.12pmc programmable clock register name: pmc_pckx address: 0x400e0440 access: read/write this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? css: master clock source selection ? pres: programmable clock prescaler 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? pres ? css value name description 0 slow_clk slow clock is selected 1 main_clk main clock is selected 2 plla_clk plla clock is selected 3 pllb_clk pllb clock is selected 4m c k m a s t e r c l o ck is selected value name description 0 clk_1 selected clock 1 clk_2 selected clock divided by 2 2 clk_4 selected clock divided by 4 3 clk_8 selected clock divided by 8 4 clk_16 selected clock divided by 16 5 clk_32 selected clock divided by 32 6 clk_64 selected clock divided by 64
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 594 30.18.13pmc interrupt enable register name: pmc_ier address: 0x400e0460 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? moscxts: main crystal oscill ator status interrupt enable ? locka: plla lock interrupt enable ? lockb: pllb lock interrupt enable ? mckrdy: master clock ready interrupt enable ? pckrdyx: programmable cloc k ready x interrupt enable ? moscsels: main oscillator sel ection status interrupt enable ? moscrcs: main on-chip rc status interrupt enable ? cfdev: clock failure detector event interrupt enable ? xt32kerr: slow crystal osci llator error interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? xt32kerr ? ? cfdev moscrcs moscsels 15 14 13 12 11 10 9 8 ?????p c k r d y 2p c k r d y 1p c k r d y 0 76543210 ????m c k r d yl o c k bl o c k am o s c x t s
595 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.14pmc interrupt disable register name: pmc_idr address: 0x400e0464 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? moscxts: main crystal oscillator status interrupt disable ? locka: plla lock interrupt disable ? lockb: pllb lock interrupt disable ? mckrdy: master clock re ady interrupt disable ? pckrdyx: programmable cloc k ready x interrupt disable ? moscsels: main oscillator sel ection status interrupt disable ? moscrcs: main on-chip rc status interrupt disable ? cfdev: clock failure detector event interrupt disable ? xt32kerr: slow crystal osci llator error interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? xt32kerr ? ? cfdev moscrcs moscsels 15 14 13 12 11 10 9 8 ?????p c k r d y 2p c k r d y 1p c k r d y 0 76543210 ????m c k r d yl o c k bl o c k am o s c x t s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 596 30.18.15pmc status register name: pmc_sr address: 0x400e0468 access: read-only ? moscxts: main crystal oscillator status 0: main crystal oscillator is not stabilized. 1: main crystal oscillator is stabilized. ? locka: plla lock status 0: plla is not locked 1: plla is locked. ? lockb: pllb lock status 0: pllb is not locked 1: pllb is locked. ? mckrdy: master clock status 0: master clock is not ready. 1: master clock is ready. ? oscsels: slow clock oscillator selection 0: internal slow clock rc oscillator is selected. 1: external slow clock 32 khz oscillator is selected. ? pckrdyx: programmabl e clock ready status 0: programmable clock x is not ready. 1: programmable clock x is ready. ? moscsels: main oscillator selection status 0: selection is in progress. 1: selection is done. ? moscrcs: main on-chip rc oscillator status 0: main on-chip rc oscillator is not stabilized. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? xt32kerr fos cfds cfdev moscrcs moscsels 15 14 13 12 11 10 9 8 ?????p c k r d y 2p c k r d y 1p c k r d y 0 76543210 oscsels ? ? ? mckrdy lockb locka moscxts
597 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1: main on-chip rc o scillator is stabilized. ? cfdev: clock failure detector event 0: no clock failure detection of the fast crystal oscillator cl ock has occurred since th e last read of pmc_sr. 1: at least one clock failure detection of the fast crystal oscillator clock has o ccurred since the last read of pmc_sr. ? cfds: clock failure detector status 0: a clock failure of the fast crys tal oscillator clock is not detected. 1: a clock failure of the fast cr ystal oscillator cl ock is detected. ? fos: clock failure detector fault output status 0: the fault output of the cloc k failure detector is inactive. 1: the fault output of the clock failure detector is active. ? xt32kerr: slow crystal oscillator error 0: the frequency of the sl ow crystal oscillator is correct (32768 hz +/- 1%) or the monitoring is disabled. 1: the frequency of the slow crystal oscillator is incorrect or has been incorrect for an el apsed period of time since the monitoring has been enabled.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 598 30.18.16pmc interrupt mask register name: pmc_imr address: 0x400e046c access: read-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? moscxts: main crystal oscillator status interrupt mask ? locka: plla lock interrupt mask ? lockb: pllb lock interrupt mask ? mckrdy: master clock ready interrupt mask ? pckrdyx: programmable cloc k ready x interrupt mask ? moscsels: main oscillator se lection status interrupt mask ? moscrcs: main on-chip rc status interrupt mask ? cfdev: clock failure detector event interrupt mask ? xt32kerr: slow crystal os cillator error interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? xt32kerr ? ? cfdev moscrcs moscsels 15 14 13 12 11 10 9 8 ?????p c k r d y 2p c k r d y 1p c k r d y 0 76543210 ????m c k r d yl o c k bl o c k am o s c x t s
599 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.17pmc fast startup mode register name: pmc_fsmr address: 0x400e0470 access: read/write this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? fstt0 - fstt15: fast startup input enable 0 to 15 0: the corresponding wake-up input has no effect on the power management controller. 1: the corresponding wake-up input enables a fast restart signal to the power management controller. ? rttal: rtt alarm enable 0: the rtt alarm has no effect on the power management controller. 1: the rtt alarm enables a fast restart signal to the power management controller. ? rtcal: rtc alarm enable 0: the rtc alarm has no effect on the power management controller. 1: the rtc alarm enables a fast restart signal to the power management controller. ? lpm: low-power mode 0: the waitforinterrupt (wfi) or the waitforevent (wfe) in struction of the processor makes the processor enter sleep mode. 1: the waitforevent (wfe) instruction of the processor makes the system to enter wait mode. ? flpm: flash low-power mode 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? flpm lpm ? ? rtcal rttal 15 14 13 12 11 10 9 8 fstt15 fstt14 fstt13 fstt12 fstt11 fstt10 fstt9 fstt8 76543210 fstt7 fstt6 fstt5 fstt4 fstt3 fstt2 fstt1 fstt0 value name description 0 flash_standby flash is in standby mode when system enters wait mode 1 flash_deep_powerdown flash is in deep-power-down mode when system enters wait mode 2 flash_idle idle mode
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 600 30.18.18pmc fast startup polarity register name: pmc_fspr address: 0x400e0474 access: read/write this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? fstpx: fast startup input polarityx defines the active polarity of the corresponding wake-up input. if the corresponding wake-up input is enabled and at the fstp level, it enables a fast restart signal. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 fstp15 fstp14 fstp13 fstp12 fstp11 fstp10 fstp9 fstp8 76543210 fstp7 fstp6 fstp5 fstp4 fstp3 fstp2 fstp1 fstp0
601 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.19pmc coprocessor fast startup mode register name: pmc_cpfsmr address: 0x400e047c access: read/write this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? fstt0 - fstt15: fast startup input enable 0 to 15 0: the corresponding wake-up input has no effect on the power management controller. 1: the corresponding wake-up input enables a fast restart signal to the power management controller. ? rttal: rtt alarm enable 0: the rtt alarm has no effect on the power management controller. 1: the rtt alarm enables a fast restart signal to the power management controller. ? rtcal: rtc alarm enable 0: the rtc alarm has no effect on the power management controller. 1: the rtc alarm enables a fast restart signal to the power management controller. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ??????r t c a lr t t a l 15 14 13 12 11 10 9 8 fstt15 fstt14 fstt13 fstt12 fstt11 fstt10 fstt9 fstt8 76543210 fstt7 fstt6 fstt5 fstt4 fstt3 fstt2 fstt1 fstt0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 602 30.18.20pmc fault output clear register name: pmc_focr address: 0x400e0478 access: write-only ? foclr: fault output clear clears the clock failure detector fault output. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????f o c l r
603 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.21pmc write protection mode register name: pmc_wpmr address: 0x400e04e4 access: read/write ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x504d43 (? pmc? in ascii). 1: enables the write protecti on if wpkey corres ponds to 0x504d43 (?pmc? in ascii). see section 30.17 ?register write protection? for the list of registers t hat can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x504d43 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0 .
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 604 30.18.22pmc write protection status register name: pmc_wpsr address: 0x400e04e8 access: read-only ? wpvs: write protection violation status 0: no write protection violation has occu rred since the last read of the pmc_wpsr. 1: a write protection violation has occurr ed since the last read of the pmc_wpsr . if this violation is an unauthorized attempt to write a prot ected register, the asso ciated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at whic h a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
605 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.23pmc peripheral clock enable register 1 name: pmc_pcer1 address: 0x400e0500 access: write-only this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? pidx: peripheral clock x enable 0: no effect. 1: enables the corresponding peripheral clock. notes: 1. to get pidx, refer to identifiers as defined in the section ?peripheral i dentifiers? in the product datasheet. 2. programming the control bits of the pe ripheral id that are not implemented has no effect on the behavior of the pmc. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????p i d 4 3p i d 4 2p i d 4 1p i d 4 0 76543210 pid39 pid38 pid37 pid36 pid35 pid34 pid33 pid32
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 606 30.18.24pmc peripheral clock disable register 1 name: pmc_pcdr1 address: 0x400e0504 access: write-only this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? pidx: peripheral clock x disable 0: no effect. 1: disables the corresponding peripheral clock. note: to get pidx, refer to identifiers as defined in the section ?peripheral identifiers ? in the product datasheet. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????p i d 4 3p i d 4 2p i d 4 1p i d 4 0 76543210 pid39 pid38 pid37 pid36 pid35 pid34 pid33 pid32
607 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.18.25pmc peripheral clock status register 1 name: pmc_pcsr1 address: 0x400e0508 access: read-only ? pidx: peripheral clock x status 0: the corresponding peripheral clock is disabled. 1: the corresponding peripheral clock is enabled. note: to get pidx, refer to identifiers as defined in the section ?peripheral identifiers ? in the product datasheet. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????p i d 4 3p i d 4 2p i d 4 1p i d 4 0 76543210 pid39 pid38 pid37 pid36 pid35 pid34 pid33 pid32
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 608 30.18.26pmc oscillator calibration register name: pmc_ocr address: 0x400e0510 access: read/write this register can only be writt en if the wpen bit is cleared in pmc write protection mode register . ? cal4: rc oscillator calibration bits for 4 mhz calibration bits applied to the rc oscillator when sel4 is set. ? sel4: selection of rc oscillator calibration bits for 4 mhz 0: default value stored in flash memory. 1: value written by user in cal4 field of this register. ? cal8: rc oscillator calibration bits for 8 mhz calibration bits applied to the rc oscillator when sel8 is set. ? sel8: selection of rc oscillator calibration bits for 8 mhz 0: factory-determined value stored in flash memory. 1: value written by user in cal8 field of this register. ? cal12: rc oscillato r calibration bits for 12 mhz calibration bits applied to the rc oscillator when sel12 is set. ? sel12: selection of rc oscillato r calibration bits for 12 mhz 0: factory-determined value stored in flash memory. 1: value written by user in cal12 field of this register. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 sel12 cal12 15 14 13 12 11 10 9 8 sel8 cal8 76543210 sel4 cal4
609 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 31. chip identifier (chipid) 31.1 description chip identifier (c hipid) registers permit recogniti on of the device and its revisi on. these registers provide the sizes and types of the on-chip memories, as well as the set of embedded peripherals. two chip identifier registers are embedded: chipid_cid r (chip id register) and chipid_exid (extension id). both registers contain a hard-wired val ue that is read-only. the first regi ster contains the following fields: ? ext: shows the use of the extension identifier register ? nvptyp and nvpsiz: identify the type of embe dded non-volatile memory and the size ? arch: identifies the set of embedded peripherals ? sramsiz: indicates the size of the embedded sram ? eproc: indicates the embedded arm processor ? version: identifies the revision of the silicon the second register is device-depende nt and reads 0 if the bit ext is 0. 31.2 embedded characteristics ? chip id registers ? identification of the device revision, sizes of the embedded memories, set of peripherals, embedded processor table 31-1. sam4cm chip id registers chip name chipid_ cidr chipid_exid sam4cmp32c (rev a) 0xa64d_0ee0 0x1 sam4cmp16c (rev a) 0xa64c_0ce0 0x1 sam4cmp8c (rev a) 0xa64c_0ae0 0x1 sam4cmp16c (rev b) 0xa64c_0ce1 0x1 sam4cmp8c (rev b) 0xa64c_0ae1 0x1 sam4cms32c (rev a) 0xa64d_0ee0 0x2 sam4cms16c (rev a) 0xa64c_0ce0 0x2 sam4cms8c (rev a) 0xa64c_0ae0 0x2 sam4cms16c (rev b) 0xa64c_0ce1 0x2 sam4cms8c (rev b) 0xa64c_0ae1 0x2
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 610 31.3 chip identifier (chipid) user interface table 31-2. register mapping offset register name access reset 0x0 chip id register chipid_cidr read-only ? 0x4 chip id extension register chipid_exid read-only ?
611 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 31.3.1 chip id register name: chipid_cidr address: 0x400e0740 access: read-only ? version: version of the device current version of the device. ? eproc: embedded processor ? nvpsiz: nonvolatile program memory size 31 30 29 28 27 26 25 24 ext nvptyp arch 23 22 21 20 19 18 17 16 arch sramsiz 15 14 13 12 11 10 9 8 nvpsiz2 nvpsiz 76543210 eproc version value name description 1 arm946es arm946es 2 arm7tdmi arm7tdmi 3 cm3 cortex-m3 4 arm920t arm920t 5 arm926ejs arm926ejs 6c a 5 c o r t e x - a 5 7 cm4 cortex-m4 value name description 0n o n e n o n e 18 k 8 k b y t e s 2 16k 16 kbytes 3 32k 32 kbytes 4? r e s e r v e d 5 64k 64 kbytes 6? r e s e r v e d 7 128k 128 kbytes 8 160k 160 kbytes 9 256k 256 kbytes 10 512k 512 kbytes 11 ? reserved
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 612 ? nvpsiz2: second nonvolatile progra m memory size ? sramsiz: internal sram size 12 1024k 1024 kbytes 13 ? reserved 14 2048k 2048 kbytes 15 ? reserved value name description 0 none none 18 k 8 k b y t e s 2 16k 16 kbytes 3 32k 32 kbytes 4? r e s e r v e d 5 64k 64 kbytes 6? r e s e r v e d 7 128k 128 kbytes 8? r e s e r v e d 9 256k 256 kbytes 10 512k 512 kbytes 11 ? reserved 12 1024k 1024 kbytes 13 ? reserved 14 2048k 2048 kbytes 15 ? reserved value name description 0 48k 48 kbytes 1 192k 192 kbytes 2 384k 384 kbytes 36 k 6 k b y t e s 4 24k 24 kbytes 54 k 4 k b y t e s 6 80k 80 kbytes 7 160k 160 kbytes 88 k 8 k b y t e s 9 16k 16 kbytes 10 32k 32 kbytes 11 64k 64 kbytes 12 128k 128 kbytes value name description
613 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? arch: architecture identifier ? nvptyp: nonvolatile program memory type ? ext: extension flag 0: chip id has a single register definition without extension. 1: an extended chip id exists. 13 256k 256 kbytes 14 96k 96 kbytes 15 512k 512 kbytes value name description 0x64 sam4cxxc sam4cxc (100-pin version) value name description 0r o m r o m 1 romless romless or on-chip flash 2 flash embedded flash memory 3 rom_flash rom and embedded flash memory ? nvpsiz is rom size ? nvpsiz2 is flash size 4 sram sram emulating rom value name description
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 614 31.3.2 chip id extension register name: chipid_exid address: 0x400e0744 access: read-only ? exid: chip id extension this bit is cleared if the ext bit in chipid_cidr is 0. 31 30 29 28 27 26 25 24 exid 23 22 21 20 19 18 17 16 exid 15 14 13 12 11 10 9 8 exid 76543210 exid 0x1 sam4cmp sam4c + 3-phase emafe 0x2 sam4cms sam4c + 2-phase emafe
615 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32. parallel input/outp ut (pio3) controller 32.1 description the parallel input/output controller (pio) manages up to 32 fully programmable input/output lines. each i/o line may be dedicated as a general-purpose i/o or be assigned to a function of an embedded peripheral. this assures effective optimization of the pins of the product. each i/o line is associated with a bit number in all of the 32-bit registers of the 32-bit wide user interface. each i/o line of the pio controller features: ? an input change interrupt enabling level change detection on any i/o line. ? additional interrupt modes enabling ri sing edge, falling edge, low-level or high-level detection on any i/o line. ? a glitch filter providing reject ion of glitches lower than one-half of peripheral clock cycle. ? a debouncing filter providing rejection of unwan ted pulses from key or push button operations. ? multi-drive capability simila r to an open drain i/o line. ? control of the pull-up and pull-down of the i/o line. ? input visibility an d output control. the pio controller also features a synchronous output prov iding up to 32 bits of data output in a single write operation.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 616 32.2 embedded characteristics ? up to 32 programmable i/o lines ? fully programmable through set/clear registers ? multiplexing of four peripheral functions per i/o line ? for each i/o line (whether assigned to a pe ripheral or used as general purpose i/o) ? input change interrupt ? programmable glitch filter ? programmable debouncing filter ? multi-drive option enables driving in open drain ? programmable pull-up on each i/o line ? pin data status register, supplies visib ility of the level on the pin at any time ? additional interrupt modes on a programmable event: rising edge, falling edge, low-level or high- level ? synchronous output, provides set and clear of several i/o lines in a single write ? register write protection ? programmable schmitt trigger inputs ? programmable i/o drive
617 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.3 block diagram figure 32-1. block diagram 32.4 product dependencies 32.4.1 pin multiplexing each pin is configurable, depending on the product, as ei ther a general-purpose i/o line only, or as an i/o line multiplexed with one or two peripheral i/os. as the multip lexing is hardware defined and thus product-dependent, the hardware designer and programmer must carefully dete rmine the configuration of the pio controllers required by their application. when an i/o line is general-purpose only, i.e., not multiplexed with any peripheral i/o, programming of the pio controller regarding the assignment to a peripheral has no effect and only the pio controller can control how the pin is driven by the product. 32.4.2 power management the power management controller controls the peripheral clock in order to save power. writing any of the registers of the user interface does not require the peripheral clock to be enabled. this means that the configuration of the i/o lines does not r equire the peripheral clock to be enabled. however, when the clock is disabled, not all of the features of the pio controller are available, including glitch filtering. note that the input change interrupt, the interrupt modes on a programmable event and the read of the pin level require the clock to be validated. embedded peripheral embedded peripheral pio interrupt pio controller up to 32 pins pmc up to 32 peripheral ios up to 32 peripheral ios peripheral clock apb interrupt controller data, enable pin 31 pin 1 pin 0 data, enable
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 618 after a hardware reset, the peripheral clock is disabled by default. the user must configure the power management contro ller before any access to the input line information. 32.4.3 interrupt generation for interrupt handling, the pio controllers are considered as user peripherals. this means that the pio controller interrupt lines are connected among the interrupt sources. refer to the pio controller peripheral identifier in the peripheral identifiers table to identify the interrupt s ources dedicated to the pio controllers. using the pio controller requires the interrupt controller to be programmed first. the pio controller interrupt can be generated only if the peripheral clock is enabled.
619 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.5 functional description the pio controller features up to 32 fully-programmable i/o lines. most of the control logic associated to each i/o is represented in figure 32-2 . in this description each signal shown represents one of up to 32 possible indexes. figure 32-2. i/o line control logic 32.5.1 pull-up and pull-down resistor control each i/o line is designed with an embedded pull-up resistor and an embedded pull-down resistor. the pull-up resistor can be enabled or disabled by writing to the pull-up enable register (pio _puer) or pull-up disable register (pio_pudr), respectively. writing to these regist ers results in setting or clea ring the corresponding bit in the pull-up status register (pio_pusr). reading a one in pio_pusr means the pull-up is disabled and reading a zero means the pull-up is enabled. the pull-down resistor can be enabled or disabled by writing the pull-down enable register (pio_ppder) or the pull-down disable register (pio_ppddr), respectively. writing in these 1 0 1 0 1 0 1 0 dq dq dff 1 0 1 0 11 00 01 10 programmable glitch or debouncing filter pio_pdsr[0] pio_isr[0] pio_idr[0] pio_imr[0] pio_ier[0] pio interrupt (up to 32 possible inputs) pio_isr[31] pio_idr[31] pio_imr[31] pio_ier[31] pad pio_pudr[0] pio_pusr[0] pio_puer[0] pio_mddr[0] pio_mdsr[0] pio_mder[0] pio_codr[0] pio_odsr[0] pio_sodr[0] pio_pdr[0] pio_psr[0] pio_per[0] pio_abcdsr1[0] pio_odr[0] pio_osr[0] pio_oer[0] peripheral clock resynchronization stage peripheral a input peripheral d output enable peripheral a output enable event detector dff pio_ifdr[0] pio_ifsr[0] pio_ifer[0] peripheral clock clock divider pio_ifscsr[0] pio_ifscer[0] pio_ifscdr[0] pio_scdr slow clock peripheral b output enable peripheral c output enable 11 00 01 10 peripheral d output peripheral a output peripheral b output peripheral c output pio_abcdsr2[0] peripheral b input peripheral c input peripheral d input pio_ppddr[0] pio_ppdsr[0] pio_ppder[0] vdd gnd integrated pull-down resistor integrated pull-up resistor div_slck
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 620 registers results in setting or clearing the correspondi ng bit in the pull-down status register (pio_ppdsr). reading a one in pio_ppdsr means the pull-up is disabl ed and reading a zero means the pull-down is enabled. enabling the pull-down resistor while th e pull-up resistor is still enabled is not possible. in this case, the write of pio_ppder for the relevant i/o line is discarded. likewise, enabling the pull-up resistor while the pull-down resistor is still enabled is not possible. in this case, the write of pio_puer for the relevant i/o line is discarded. control of the pull-up resistor is possible regardless of the configuration of the i/o line. after reset, depending on the i/o, pull-up or pull-down can be set. 32.5.2 i/o line or peripheral function selection when a pin is multiplexed with one or two peripheral functi ons, the selection is contro lled with the enable register (pio_per) and the disable register (pio_pd r). the status register (pio_psr) is the result of the set and clear registers and indicates whether the pin is controlled by the corresponding peripheral or by the pio controller. a value of zero indicates that the pin is controlled by the corresponding on-chip peripheral selected in the abcd select registers (pio_abcdsr1 and pio_abcdsr2). a valu e of one indicates the pin is controlled by the pio controller. if a pin is used as a general-purpose i/o line (not multiplexed with an on-chip peripheral), pio_per and pio_pdr have no effect and pio_psr returns a one for the corresponding bit. after reset, the i/o lines are controlled by the pio controller, i.e., pio_psr resets at one. however, in some events, it is important that pio lines are controlled by the peripheral (as in the case of memory chip select lines that must be driven inactive after reset, or for address lines that must be driven low for booting out of an external memory). thus, the reset value of pio_psr is defined at the product level and depends on the multiplexing of the device. 32.5.3 peripheral a or b or c or d selection the pio controller provides multiplexing of up to fo ur peripheral functions on a single pin. the selection is performed by writing pio_ abcdsr1 and pio_abcdsr2. for each pin: ? the corresponding bit at level zero in pio_abcdsr1 and the corresponding bit at level zero in pio_abcdsr2 means peripheral a is selected. ? the corresponding bit at level one in pio_abcdsr1 and the corresponding bit at level zero in pio_abcdsr2 means peripheral b is selected. ? the corresponding bit at level zero in pio_abcdsr1 and the corresponding bit at level one in pio_abcdsr2 means peripheral c is selected. ? the corresponding bit at level one in pio_abcdsr1 and the corresponding bit at level zero in pio_abcdsr2 means peripheral d is selected. note that multiplexing of peripheral li nes a, b, c and d only affects the outp ut line. the peripheral input lines are always connected to the pin input (see figure 32-2 on page 619 ). writing in pio_abcdsr1 and pio_abcds r2 manages the multiplexing regardless of the configuration of the pin. however, assignment of a pin to a peripheral f unction requires a write in pio_abcdsr1 and pio_abcdsr2 in addition to a write in pio_pdr. after reset, pio_abcdsr1 and pio_abcdsr2 are zero, thus indicating t hat all the pio lines are configured on peripheral a. however, peripheral a generally does not dr ive the pin as the pio contro ller resets in i/o line mode. if the software selects a peripheral a, b, c or d which does not exist for a pin, no alternate functions are enabled for this pin and the selection is taken into account. the pio controller does not carry out checks to prevent selection of a peripheral which does not exist.
621 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.5.4 output control when the i/o line is assigned to a peripheral function, i.e., the corresponding bit in pio_psr is at zero, the drive of the i/o line is controlled by the peripheral. peripheral a or b or c or d depending on the value in pio_abcdsr1 and pio_abcdsr2 determines whether the pin is driven or not. when the i/o line is controlled by the pio controller, the pin can be configured to be driven. this is done by writing the output enable register (pio_oer ) and output disable register (pio_ odr). the results of these write operations are detected in the output status register (pio_osr). when a bit in this register is at zero, the corresponding i/o line is used as an input only. when the bit is at one, the corresponding i/o line is driven by the pio controller. the level driven on an i/o line can be determined by writ ing in the set output data register (pio_sodr) and the clear output data register (pio_codr). these write ope rations, respectively, set and clear the output data status register (pio_odsr), which represents the data driven on the i/o lines. writing in pio_oer and pio_odr manages pio_osr whether the pi n is configured to be controlled by the pio controller or assigned to a peripheral function. this enables configuration of the i/o line prior to setting it to be managed by the pio controller. similarly, writing in pio_so dr and pio_codr affects pio_odsr. this is important as it defines the first level driven on the i/o line. 32.5.5 synchronous data output clearing one or more pio line(s) and setting another one or more pio line(s) synchronously cannot be done by using pio_sodr and pio_codr. it requires two successive write operations into two different registers. to overcome this, the pio controller offers a direct control of pio outputs by single write access to pio_odsr. only bits unmasked by the output write st atus register (pio_owsr) are written. the mask bits in pio_owsr are set by writing to the output write enable register (pio_ower) and cleared by writing to the outp ut write disable register (pio_owdr). after reset, the synchronous data output is disabled on all the i/o lines as pio_owsr resets at 0x0. 32.5.6 multi-drive control (open drain) each i/o can be independently programmed in open drain by using the multi-drive feat ure. this feature permits several drivers to be connected on the i/o line which is driv en low only by each device. an external pull-up resistor (or enabling of the internal one) is generally required to guarantee a high level on the line. the multi-drive feature is controlled by the multi-driver enable register (pio_mder) and the multi-driver disable register (pio_mddr). the multi-drive can be selected whether the i/o line is controlled by the pio controller or assigned to a peripheral function. the multi-driver stat us register (pio_mdsr) indi cates the pins that are configured to support external drivers. after reset, the multi-drive feature is disabled on all pins, i.e., pio_mdsr resets at value 0x0. 32.5.7 output line timings figure 32-3 shows how the outputs are driven either by writi ng pio_sodr or pio_codr, or by directly writing pio_odsr. this last case is valid only if the corresponding bit in pio_owsr is set. figure 32-3 also shows when the feedback in the pin data status register (pio_pdsr) is available.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 622 figure 32-3. output line timings 32.5.8 inputs the level on each i/o line can be read through pio_pdsr. this register indicates the level of the i/o lines regardless of their configuration, whether uniquely as an input, or driven by the pio controller, or driven by a peripheral. reading the i/o line levels requires the clock of the pi o controller to be enabled, otherwise pio_pdsr reads the levels present on the i/o line at the time the clock was disabled. 32.5.9 input glitch and debouncing filters optional input glitch and debouncing filters are independently programmable on each i/o line. the glitch filter can filter a glitch wit h a duration of less than 1/2 peripheral clock and the debounc ing filter can filter a pulse of less than 1/2 period of a programmable divided slow clock. the selection between glitch filtering or debounce filterin g is done by writing in the pio input filter slow clock disable register (pio_ifscdr) and the pio input filter slow clock enable register (pio_ifscer). writing pio_ifscdr and pio_ifscer, respectively, sets and clears bits in the input filter slow clock status register (pio_ifscsr). the current selection status can be checked by reading the pio_ifscsr. ? if pio_ifscsr[i] = 0: the glitch filter can filter a glitch with a duration of less than 1/2 master clock period. ? if pio_ifscsr[i] = 1: the debouncing filter can filter a pulse with a duration of less than 1/2 programmable divided slow clock period. for the debouncing filter, the period of t he divided slow clock is defined by writ ing in the div field of the slow clock divider debouncing register (pio_scdr): t div_slck = ((div + 1) 2) t slck when the glitch or debouncing filter is enabled, a glitch or pulse with a duration of less than 1/2 selected clock cycle (selected clock represents peripheral clock or divided slow clock depending on pio_ifscdr and pio_ifscer programming) is automatic ally rejected, while a pulse with a duration of one selected clock (peripheral clock or divided slow clock) cycle or more is accepted. for pulse duratio ns between 1/2 selected clock cycle and one selected clock cycle, the pulse may or ma y not be taken into account, depending on the precise timing of its occurrence. thus for a pulse to be visible, it must exceed one selected cl ock cycle, whereas for a glitch to be reliably filtered out, its duration must not exceed 1/2 selected clock cycle. the filters also introduce so me latencies, illustrated in figure 32-4 and figure 32-5 . 2 cycles apb access 2 cycles apb access peripheral clock write pio_sodr write pio_odsr at 1 pio_odsr pio_pdsr write pio_codr write pio_odsr at 0
623 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the glitch filters are controlled by the input filter en able register (pio_ifer), the input filter disable register (pio_ifdr) and the input filter status register (p io_ifsr). writing pi o_ifer and pio_ifdr respectively sets and clears bits in pio_ifsr. th is last register enables the glitch filter on the i/o lines. when the glitch and/or debouncing filter is enabled, it does not modify the beha vior of the inputs on the peripherals. it acts only on the val ue read in pio_pdsr and on the input cha nge interrupt detection. the glitch and debouncing filters require that the peripheral clock is enabled. figure 32-4. input glitch filter timing figure 32-5. input debouncing filter timing 32.5.10 input edge/level interrupt the pio controller can be programmed to generate an inte rrupt when it detects an edge or a level on an i/o line. the input edge/level interrupt is controlled by writing the interrupt enable register (pio_ier) and the interrupt disable register (pio_idr), which enable and disable th e input change interrupt respectively by setting and clearing the corresponding bit in the interrupt mask regist er (pio_imr). as input change detection is possible only by comparing two successive samplings of the input of the i/o line, the peripheral clock must be enabled. the input change interrupt is available regardless of the configur ation of the i/o line, i.e., configured as an input only, controlled by the pio controller or as signed to a peripheral function. by default, the interrupt can be generated at any time an edge is detected on the input. some additional interrupt modes can be enabled/disabled by writing in the additional interrupt modes enable register (pio_aimer) and additional interrupt modes dis able register (pio_aimdr). the current state of this selection can be read through the additional interrupt modes mask register (pio_aimmr). these additional modes are: peripheral clcok pin level pio_pdsr if pio_ifsr = 0 pio_pdsr if pio_ifsr = 1 1 cycle 1 cycle 1 cycle up to 1.5 cycles 2 cycles up to 2.5 cycles up to 2 cycles 1 cycle 1 cycle pio_ifcsr = 0 divided slow clock (div_slck) pin level pio_pdsr if pio_ifsr = 0 pio_pdsr if pio_ifsr = 1 1 cycle t div_slck up to 1.5 cycles t div_slck 1 cycle t div_slck up to 2 cycles t peripheral clock up to 2 cycles t peripheral clock up to 2 cycles t peripheral clock up to 2 cycles t peripheral clock up to 1.5 cycles t div_slck pio_ifcsr = 1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 624 ? rising edge detection ? falling edge detection ? low-level detection ? high-level detection in order to select an a dditional interrupt mode: ? the type of event detection (edge or level) must be selected by writing in t he edge select register (pio_esr) and level select register (pio_lsr) which select, respectively, the edge and level detection. the current status of this selection is accessible through the edge/level status register (pio_elsr). ? the polarity of the event detection (rising/falling edge or high/low-level) must be selected by writing in the falling edge/low-level sele ct register (pio_fellsr) and rising edge/high- level select register (pio_rehlsr) which allow to select falling or rising edge (if edge is sele cted in pio_elsr ) edge or high- or low-level detection (if level is se lected in pio_elsr). the current stat us of this selection is accessible through the fall/rise - low/high st atus register (pio_frlhsr). when an input edge or level is detected on an i/o line, the corresponding bit in the interrupt status register (pio_isr) is set. if the corresponding bit in pio_imr is set, the pio controller interrupt line is asserted.the interrupt signals of the 32 channels are ored-wired together to generate a single interrupt signal to the interrupt controller. when the software reads pio_isr, all the interrupts are autom atically cleared. this sign ifies that all the interrupts that are pending when pio_isr is read must be handled. when an interrupt is enabled on a ?level?, the interrupt is generated as long as the interrupt source is not cleared, even if some read accesses in pio_isr are performed.
625 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 32-6. event detector on input lines (figure represents line 0) example of interrupt generation on following lines: ? rising edge on pio line 0 ? falling edge on pio line 1 ? rising edge on pio line 2 ? low-level on pio line 3 ? high-level on pio line 4 ? high-level on pio line 5 ? falling edge on pio line 6 ? rising edge on pio line 7 ? any edge on the other lines table 32-1 details the required configuration for this example. event detector 0 1 0 1 1 0 0 1 edge detector falling edge detector rising edge detector pio_fellsr[0] pio_frlhsr[0] pio_rehlsr[0] low level detector high level detector pio_esr[0] pio_elsr[0] pio_lsr[0] pio_aimdr[0] pio_aimmr[0] pio_aimer[0] event detection on line 0 resynchronized input on line 0 table 32-1. configuration for example interr upt generation configuration description interrupt mode all the interrupt sources are enabled by writing 32?hffff_ffff in pio_ier. then the additional interrupt mode is enabled for lines 0 to 7 by writing 32?h0000_00ff in pio_aimer. edge or level detection lines 3, 4 and 5 are configured in level det ection by writing 32?h0000_0038 in pio_lsr. the other lines are configured in edge detection by default, if they ha ve not been previously configured. otherwise, lines 0, 1, 2, 6 and 7 must be configured in edge detection by writing 32?h0000_00c7 in pio_esr. falling/rising edge or low/high-level detection lines 0, 2, 4, 5 and 7 are configured in risi ng edge or high-level detection by writing 32?h0000_00b5 in pio_rehlsr. the other lines are configured in falling edge or low-level detection by default if they have not been previously configured. otherwise, lines 1, 3 and 6 must be configured in falling edge/low-level detection by writ ing 32?h0000_004a in pio_fellsr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 626 figure 32-7. input change interrupt timing s when no additional interrupt modes 32.5.11 programmable i/o drive it is possible to configure the i/o drive for pads pa0 to pa31. refer to the section ?electrical characteristics?. 32.5.12 programmable schmitt trigger it is possible to configure each input for the schmitt trigger. by default the schmitt tri gger is active. disabling the schmitt trigger is requested when using the qtouch ? library. 32.5.13 i/o lines programming example the programming example shown in table 32-2 is used to obtain the following configuration: ? 4-bit output port on i/o lines 0 to 3 (should be writte n in a single write operation), open-drain, with pull-up resistor ? four output signals on i/o lines 4 to 7 (to drive leds for example), driven high and low, no pull-up resistor, no pull-down resistor ? four input signals on i/o lines 8 to 11 (to read push-button states for example), with pull-up resistors, glitch filters and input change interrupts ? four input signals on i/o line 12 to 15 to read an external device status (po lled, thus no input change interrupt), no pull-up resi stor, no glitch filter ? i/o lines 16 to 19 assigned to peripheral a functions with pull-up resistor ? i/o lines 20 to 23 assigned to peripheral b functions with pull-down resistor ? i/o lines 24 to 27 assigned to peripheral c with input ch ange interrupt, no pull-up resistor and no pull-down resistor ? i/o lines 28 to 31 assigned to peripheral d, no pull-up resistor and no pull-down resistor peripheral clock pin level read pio_isr apb access pio_isr apb access table 32-2. programming example register value to be written pio_per 0x0000_ffff pio_pdr 0xffff_0000 pio_oer 0x0000_00ff pio_odr 0xffff_ff00 pio_ifer 0x0000_0f00 pio_ifdr 0xffff_f0ff pio_sodr 0x0000_0000 pio_codr 0x0fff_ffff
627 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 pio_ier 0x0f00_0f00 pio_idr 0xf0ff_f0ff pio_mder 0x0000_000f pio_mddr 0xffff_fff0 pio_pudr 0xfff0_00f0 pio_puer 0x000f_ff0f pio_ppddr 0xff0f_ffff pio_ppder 0x00f0_0000 pio_abcdsr1 0xf0f0_0000 pio_abcdsr2 0xff00_0000 pio_ower 0x0000_000f pio_owdr 0x0fff_ fff0 table 32-2. programming example (continued)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 628 32.5.14 register write protection to prevent any single software error from corrupting pio behavior, certain registers in the address space can be write-protected by settin g the wpen bit in the pio write protection mode register (pio_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the pio write protection status register (pio_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically clea red after readin g the pio_wpsr. the following registers can be write-protected: ? pio enable register ? pio disable register ? pio output enable register ? pio output disable register ? pio input filter enable register ? pio input filter disable register ? pio multi-driver enable register ? pio multi-driver disable register ? pio pull-up disable register ? pio pull-up enable register ? pio peripheral abcd select register 1 ? pio peripheral abcd select register 2 ? pio output write enable register ? pio output write disable register ? pio pad pull-down disable register ? pio pad pull-down status register
629 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6 parallel input/output contro ller (pio) user interface each i/o line controlled by the pio cont roller is associated with a bit in each of the pio controller user interface registers. each register is 32 bits wide. if a parallel i/o line is not defined, writing to the corresponding bits has no effect. undefined bits read zero. if the i/o line is not mult iplexed with any peripheral, the i/o line is controlled by the pio controller and pio_psr returns one systematically. table 32-3. register mapping offset register name access reset 0x0000 pio enable register pio_per write-only ? 0x0004 pio disable register pio_pdr write-only ? 0x0008 pio status register pio_psr read-only (1) 0x000c reserved ? ? ? 0x0010 output enable register pio_oer write-only ? 0x0014 output disable register pio_odr write-only ? 0x0018 output status register pio_osr read-only 0x00000000 0x001c reserved ? ? ? 0x0020 glitch input filter enab le register pio_ifer write-only ? 0x0024 glitch input filter dis able register pio_ifdr write-only ? 0x0028 glitch input filter status register pio_ifsr read-only 0x00000000 0x002c reserved ? ? ? 0x0030 set output data register pio_sodr write-only ? 0x0034 clear output data register pio_codr write-only 0x0038 output data status register pio_odsr read-only or (2) read/write ? 0x003c pin data status register pio_pdsr read-only (3) 0x0040 interrupt enable re gister pio_ier write-only ? 0x0044 interrupt disable re gister pio_idr write-only ? 0x0048 interrupt mask register pio_imr read-only 0x00000000 0x004c interrupt status register (4) pio_isr read-only 0x00000000 0x0050 multi-driver enable register pio_mder write-only ? 0x0054 multi-driver disable register pio_mddr write-only ? 0x0058 multi-driver status register pio_mdsr read-only 0x00000000 0x005c reserved ? ? ? 0x0060 pull-up disable register pio_pudr write-only ? 0x0064 pull-up enable register pio_puer write-only ? 0x0068 pad pull-up status register pio_pusr read-only (1) 0x006c reserved ? ? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 630 notes: 1. reset value depends on the product implementation. 2. pio_odsr is read-only or read/write depending on pio_owsr i/o lines. 3. reset value of pio_pdsr depends on the level of the i/o lines . reading the i/o line levels requires the clock of the pio controller to be enabled, otherwise pio_pdsr reads the levels present on the i/o line at the time the clock was disabled. 0x0070 peripheral select register 1 pio_abcdsr1 read/write 0x00000000 0x0074 peripheral select register 2 pio_abcdsr2 read/write 0x00000000 0x0078?0x007c reserved ? ? ? 0x0080 input filter slow clock disable register pio_ifscdr write-only ? 0x0084 input filter slow clock en able register pio_ifscer write-only ? 0x0088 input filter slow clock status register pio_ifscsr read-only 0x00000000 0x008c slow clock divider debouncing register pio_scdr read/write 0x00000000 0x0090 pad pull-down disable register pio_ppddr write-only ? 0x0094 pad pull-down enable register pio_ppder write-only ? 0x0098 pad pull-down status register pio_ppdsr read-only (1) 0x009c reserved ? ? ? 0x00a0 output write enable pio_ower write-only ? 0x00a4 output write disable pio_owdr write-only ? 0x00a8 output write status register pio_owsr read-only 0x00000000 0x00ac reserved ? ? ? 0x00b0 additional interrupt modes enable register pio_aimer write-only ? 0x00b4 additional interrupt modes disable register pio_aimdr write-only ? 0x00b8 additional interrupt modes mask register pio_aimmr read-only 0x00000000 0x00bc reserved ? ? ? 0x00c0 edge select register pio_esr write-only ? 0x00c4 level select register pio_lsr write-only ? 0x00c8 edge/level status register pio_elsr read-only 0x00000000 0x00cc reserved ? ? ? 0x00d0 falling edge/low-level select register pio_fellsr write-only ? 0x00d4 rising edge/high-level select register pio_rehlsr write-only ? 0x00d8 fall/rise - low/high status register pio_frlhsr read-only 0x00000000 0x00dc reserved ? ? ? 0x00e0 reserved ? ? ? 0x00e4 write protection mode register pio_wpmr read/write 0x00000000 0x00e8 write protection status re gister pio_wpsr read-only 0x00000000 0x00ec?0x00fc reserved ? ? ? 0x0100 schmitt trigger register pio_schmitt read/write 0x00000000 0x0104?0x010c reserved ? ? ? 0x0110 reserved ? ? ? 0x0114 reserved ? ? ? 0x0118 i/o drive register pio_driver read/write 0x00000000 0x011c reserved ? ? ? 0x0120?0x014c reserved ? ? ? table 32-3. register mapping (continued) offset register name access reset
631 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 4. pio_isr is reset at 0x0. however, the first read of the register may read a different value as input changes may have occurred. 5. if an offset is not listed in the tabl e it must be considered as reserved.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 632 32.6.1 pio enable register name: pio_per address: 0x400e0e00 (pioa), 0x400e1000 (piob) , 0x4800c000 (pioc), 0x400e1200 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: pio enable 0: no effect. 1: enables the pio to control the corresponding pin (disables peripheral control of the pin). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
633 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.2 pio disable register name: pio_pdr address: 0x400e0e04 (pioa), 0x400e1004 (piob) , 0x4800c004 (pioc), 0x400e1204 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: pio disable 0: no effect. 1: disables the pio from controllin g the corresponding pin (enables peripheral control of the pin). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 634 32.6.3 pio status register name: pio_psr address: 0x400e0e08 (pioa), 0x400e1008 (piob) , 0x4800c008 (pioc), 0x400e1208 (piod) access: read-only ? p0?p31: pio status 0: pio is inactive on the correspond ing i/o line (perip heral is active). 1: pio is active on the corresponding i/o line (peripheral is inactive). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
635 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.4 pio output enable register name: pio_oer address: 0x400e0e10 (pioa), 0x400e1010 (piob) , 0x4800c010 (pioc), 0x400e1210 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: output enable 0: no effect. 1: enables the output on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 636 32.6.5 pio output disable register name: pio_odr address: 0x400e0e14 (pioa), 0x400e1014 (piob) , 0x4800c014 (pioc), 0x400e1214 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: output disable 0: no effect. 1: disables the output on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
637 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.6 pio output status register name: pio_osr address: 0x400e0e18 (pioa), 0x400e1018 (piob) , 0x4800c018 (pioc), 0x400e1218 (piod) access: read-only ? p0?p31: output status 0: the i/o line is a pure input. 1: the i/o line is enabled in output. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 638 32.6.7 pio input filter enable register name: pio_ifer address: 0x400e0e20 (pioa), 0x400e1020 (piob) , 0x4800c020 (pioc), 0x400e1220 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: input filter enable 0: no effect. 1: enables the input glitch filter on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
639 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.8 pio input filter disable register name: pio_ifdr address: 0x400e0e24 (pioa), 0x400e1024 (piob) , 0x4800c024 (pioc), 0x400e1224 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: input filter disable 0: no effect. 1: disables the input glitch filter on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 640 32.6.9 pio input filter status register name: pio_ifsr address: 0x400e0e28 (pioa), 0x400e1028 (piob) , 0x4800c028 (pioc), 0x400e1228 (piod) access: read-only ? p0?p31: input filer status 0: the input glitch filter is disabled on the i/o line. 1: the input glitch filter is enabled on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
641 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.10 pio set output data register name: pio_sodr address: 0x400e0e30 (pioa), 0x400e1030 (piob) , 0x4800c030 (pioc), 0x400e1230 (piod) access: write-only ? p0?p31: set output data 0: no effect. 1: sets the data to be driven on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 642 32.6.11 pio clear output data register name: pio_codr address: 0x400e0e34 (pioa), 0x400e1034 (piob) , 0x4800c034 (pioc), 0x400e1234 (piod) access: write-only ? p0?p31: clear output data 0: no effect. 1: clears the data to be driven on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
643 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.12 pio output data status register name: pio_odsr address: 0x400e0e38 (pioa), 0x400e1038 (piob) , 0x4800c038 (pioc), 0x400e1238 (piod) access: read-only or read/write ? p0?p31: output data status 0: the data to be driven on the i/o line is 0. 1: the data to be driven on the i/o line is 1. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 644 32.6.13 pio pin data status register name: pio_pdsr address: 0x400e0e3c (pioa), 0x400e103c (piob), 0x4800c03c (pioc), 0x400e123c (piod) access: read-only ? p0?p31: output data status 0: the i/o line is at level 0. 1: the i/o line is at level 1. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
645 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.14 pio interrupt enable register name: pio_ier address: 0x400e0e40 (pioa), 0x400e1040 (piob) , 0x4800c040 (pioc), 0x400e1240 (piod) access: write-only ? p0?p31: input change interrupt enable 0: no effect. 1: enables the input change interrupt on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 646 32.6.15 pio interrupt disable register name: pio_idr address: 0x400e0e44 (pioa), 0x400e1044 (piob) , 0x4800c044 (pioc), 0x400e1244 (piod) access: write-only ? p0?p31: input change interrupt disable 0: no effect. 1: disables the input change interrupt on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
647 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.16 pio interrupt mask register name: pio_imr address: 0x400e0e48 (pioa), 0x400e1048 (piob) , 0x4800c048 (pioc), 0x400e1248 (piod) access: read-only ? p0?p31: input change interrupt mask 0: input change interrupt is disabled on the i/o line. 1: input change interrupt is enabled on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 648 32.6.17 pio interrupt status register name: pio_isr address: 0x400e0e4c (pioa), 0x400e104c (piob), 0x4800c04c (pioc), 0x400e124c (piod) access: read-only ? p0?p31: input change interrupt status 0: no input change has been detected on the i/o line since pio_isr was last read or since reset. 1: at least one input change has been detected on the i/o line since pio_isr was last read or since reset. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
649 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.18 pio multi-driver enable register name: pio_mder address: 0x400e0e50 (pioa), 0x400e1050 (piob) , 0x4800c050 (pioc), 0x400e1250 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0-p31: multi-drive enable 0: no effect. 1: enables multi-drive on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 650 32.6.19 pio multi-driver disable register name: pio_mddr address: 0x400e0e54 (pioa), 0x400e1054 (piob) , 0x4800c054 (pioc), 0x400e1254 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: multi-drive disable 0: no effect. 1: disables multi-drive on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
651 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.20 pio multi-driver status register name: pio_mdsr address: 0x400e0e58 (pioa), 0x400e1058 (piob) , 0x4800c058 (pioc), 0x400e1258 (piod) access: read-only ? p0?p31: multi-drive status 0: the multi-drive is disabled on the i/o line. the pin is driven at high- and low-level. 1: the multi-drive is enabled on the i/o line. the pin is driven at low-level only. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 652 32.6.21 pio pull-up disable register name: pio_pudr address: 0x400e0e60 (pioa), 0x400e1060 (piob) , 0x4800c060 (pioc), 0x400e1260 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: pull-up disable 0: no effect. 1: disables the pull-up resistor on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
653 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.22 pio pull-up enable register name: pio_puer address: 0x400e0e64 (pioa), 0x400e1064 (piob) , 0x4800c064 (pioc), 0x400e1264 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: pull-up enable 0: no effect. 1: enables the pull-up resistor on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 654 32.6.23 pio pull-up status register name: pio_pusr address: 0x400e0e68 (pioa), 0x400e1068 (piob) , 0x4800c068 (pioc), 0x400e1268 (piod) access: read-only ? p0?p31: pull-up status 0: pull-up resistor is enabled on the i/o line. 1: pull-up resistor is disabled on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
655 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.24 pio peripheral abcd select register 1 name: pio_abcdsr1 access: read/write this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: peripheral select if the same bit is set to 0 in pio_abcdsr2: 0: assigns the i/o line to the peripheral a function. 1: assigns the i/o line to the peripheral b function. if the same bit is set to 1 in pio_abcdsr2: 0: assigns the i/o line to the peripheral c function. 1: assigns the i/o line to the peripheral d function. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 656 32.6.25 pio peripheral abcd select register 2 name: pio_abcdsr2 access: read/write this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: peripheral select if the same bit is set to 0 in pio_abcdsr1: 0: assigns the i/o line to the peripheral a function. 1: assigns the i/o line to the peripheral c function. if the same bit is set to 1 in pio_abcdsr1: 0: assigns the i/o line to the peripheral b function. 1: assigns the i/o line to the peripheral d function. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
657 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.26 pio input filter slow clock disable register name: pio_ifscdr address: 0x400e0e80 (pioa), 0x400e1080 (piob) , 0x4800c080 (pioc), 0x400e1280 (piod) access: write-only ? p0?p31: peripheral clock glitch filtering select 0: no effect. 1: the glitch filter is able to filter glitches with a duration < t peripheral clock /2. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 658 32.6.27 pio input filter slow clock enable register name: pio_ifscer address: 0x400e0e84 (pioa), 0x400e1084 (piob) , 0x4800c084 (pioc), 0x400e1284 (piod) access: write-only ? p0?p31: slow clock debouncing filtering select 0: no effect. 1: the debouncing filter is able to filter pulses with a duration < t div_slck /2. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
659 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.28 pio input filter slow clock status register name: pio_ifscsr address: 0x400e0e88 (pioa), 0x400e1088 (piob) , 0x4800c088 (pioc), 0x400e1288 (piod) access: read-only ? p0?p31: glitch or debouncing filter selection status 0: the glitch filter is able to filter glitches with a duration < t peripheral clock /2. 1: the debouncing filter is able to filter pulses with a duration < t div_slck /2. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 660 32.6.29 pio slow clock di vider debouncing register name: pio_scdr address: 0x400e0e8c (pioa), 0x400e108c (piob), 0x4800c08c (pioc), 0x400e128c (piod) access: read/write ? div: slow clock divider selection for debouncing t div_slck = ((div + 1) 2) t slck 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?? d i v 76543210 div
661 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.30 pio pad pull-down disable register name: pio_ppddr address: 0x400e0e90 (pioa), 0x400e1090 (piob) , 0x4800c090 (pioc), 0x400e1290 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: pull-down disable 0: no effect. 1: disables the pull-down resistor on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 662 32.6.31 pio pad pull-down enable register name: pio_ppder address: 0x400e0e94 (pioa), 0x400e1094 (piob) , 0x4800c094 (pioc), 0x400e1294 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: pull-down enable 0: no effect. 1: enables the pull-down resistor on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
663 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.32 pio pad pull-down status register name: pio_ppdsr address: 0x400e0e98 (pioa), 0x400e1098 (piob) , 0x4800c098 (pioc), 0x400e1298 (piod) access: read-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: pull-down status 0: pull-down resistor is enabled on the i/o line. 1: pull-down resistor is disabled on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 664 32.6.33 pio output write enable register name: pio_ower address: 0x400e0ea0 (pioa), 0x400e10a0 (piob) , 0x4800c0a0 (pioc), 0x400e12a0 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: output write enable 0: no effect. 1: enables writing pio_odsr for the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
665 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.34 pio output write disable register name: pio_owdr address: 0x400e0ea4 (pioa), 0x400e10a4 (piob) , 0x4800c0a4 (pioc), 0x400e12a4 (piod) access: write-only this register can only be written if the wpen bit is cleared in the pio write protection mode register . ? p0?p31: output write disable 0: no effect. 1: disables writing pio_odsr for the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 666 32.6.35 pio output write status register name: pio_owsr address: 0x400e0ea8 (pioa), 0x400e10a8 (piob) , 0x4800c0a8 (pioc), 0x400e12a8 (piod) access: read-only ? p0?p31: output write status 0: writing pio_odsr does not affect the i/o line. 1: writing pio_odsr affects the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
667 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.36 pio additional interrupt modes enable register name: pio_aimer address: 0x400e0eb0 (pioa), 0x400e10b0 (piob) , 0x4800c0b0 (pioc), 0x400e12b0 (piod) access: write-only ? p0?p31: additional interrupt modes enable 0: no effect. 1: the interrupt source is the event described in pio_elsr and pio_frlhsr. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 668 32.6.37 pio additional interrupt modes disable register name: pio_aimdr address: 0x400e0eb4 (pioa), 0x400e10b4 (piob) , 0x4800c0b4 (pioc), 0x400e12b4 (piod) access: write-only ? p0?p31: additional interrupt modes disable 0: no effect. 1: the interrupt mode is set to the default interrupt mode (both-edge detection). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
669 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.38 pio additional interrupt modes mask register name: pio_aimmr address: 0x400e0eb8 (pioa), 0x400e10b8 (piob) , 0x4800c0b8 (pioc), 0x400e12b8 (piod) access: read-only ? p0?p31: io line index selects the io event type triggering an interrupt. 0: the interrupt source is a both-edge detection event. 1: the interrupt source is described by the registers pio_el sr and pio_frlhsr. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 670 32.6.39 pio edge select register name: pio_esr address: 0x400e0ec0 (pioa), 0x400e10c0 (piob), 0x4800c0c0 (pioc), 0x400e12c0 (piod) access: write-only ? p0?p31: edge interrupt selection 0: no effect. 1: the interrupt source is an edge-detection event. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
671 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.40 pio level select register name: pio_lsr address: 0x400e0ec4 (pioa), 0x400e10c4 (piob), 0x4800c0c4 (pioc), 0x400e12c4 (piod) access: write-only ? p0?p31: level inte rrupt selection 0: no effect. 1: the interrupt source is a level-detection event. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 672 32.6.41 pio edge/level status register name: pio_elsr address: 0x400e0ec8 (pioa), 0x400e10c8 (piob), 0x4800c0c8 (pioc), 0x400e12c8 (piod) access: read-only ? p0?p31: edge/level interrupt source selection 0: the interrupt source is an edge-detection event. 1: the interrupt source is a level-detection event. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
673 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.42 pio falling edge/low-level select register name: pio_fellsr address: 0x400e0ed0 (pioa), 0x400e10d0 (piob), 0x4800c0d0 (pioc), 0x400e12d0 (piod) access: write-only ? p0?p31: falling edge/low-level interrupt selection 0: no effect. 1: the interrupt source is set to a falling edge detectio n or low-level detection event, depending on pio_elsr. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 674 32.6.43 pio rising edge/hi gh-level select register name: pio_rehlsr address: 0x400e0ed4 (pioa), 0x400e10d4 (piob), 0x4800c0d4 (pioc), 0x400e12d4 (piod) access: write-only ? p0?p31: rising edge/high-level interrupt selection 0: no effect. 1: the interrupt source is set to a rising edge detection or high-level detection event, depending on pio_elsr. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
675 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.44 pio fall/rise - low/high status register name: pio_frlhsr address: 0x400e0ed8 (pioa), 0x400e10d8 (piob), 0x4800c0d8 (pioc), 0x400e12d8 (piod) access: read-only ? p0?p31: edge/level interrupt source selection 0: the interrupt source is a falling edge detection (if p io_elsr = 0) or low-level dete ction event (if pio_elsr = 1). 1: the interrupt source is a rising edge detection (if pio_ elsr = 0) or high-level detection event (if pio_elsr = 1). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 676 32.6.45 pio write protection mode register name: pio_wpmr address: 0x400e0ee4 (pioa), 0x400e10e4 (piob) , 0x4800c0e4 (pioc), 0x400e12e4 (piod) access: read/write ? wpen: write protection enable 0: disables the writ e protection if wpkey co rresponds to 0x50494f (?pio? in ascii). 1: enables the write protecti on if wpkey corres ponds to 0x50494f (?pio? in ascii). see section 32.5.14 ?register write protection? for the list of registers that can be protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x50494f passwd writing any other value in this field aborts the wr ite operation of the wpen bit. always reads as 0.
677 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.46 pio write protection status register name: pio_wpsr address: 0x400e0ee8 (pioa), 0x400e10e8 (piob) , 0x4800c0e8 (pioc), 0x400e12e8 (piod) access: read-only ? wpvs: write protection violation status 0: no write protection violation has occu rred since the last read of the pio_wpsr. 1: a write protection violation has occurred since the last read of the pio_wpsr . if this violation is an unauthorized attempt to write a prot ected register, the asso ciated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at whic h a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 678 32.6.47 pio schmitt trigger register name: pio_schmitt address: 0x400e0f00 (pioa), 0x400e1100 (piob), 0x4800c100 (pioc), 0x400e1300 (piod) access: read/write ? schmittx [x=0..31]: schmitt trigger control 0: schmitt trigger is enabled. 1: schmitt trigge r is disabled. 31 30 29 28 27 26 25 24 schmitt31 schmitt30 schmit t29 schmitt28 schmitt27 schmitt26 schmitt25 schmitt24 23 22 21 20 19 18 17 16 schmitt23 schmitt22 schmit t21 schmitt20 schmitt19 schmitt18 schmitt17 schmitt16 15 14 13 12 11 10 9 8 schmitt15 schmitt14 schmit t13 schmitt12 schmitt11 schmitt10 schmitt9 schmitt8 76543210 schmitt7 schmitt6 schmitt5 schmitt4 schmitt3 schmitt2 schmitt1 schmitt0
679 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 32.6.48 pio i/o drive register name: pio_driver address: 0x400e0f18 (pioa), 0x400e1118 (piob), 0x4800c118 (pioc), 0x400e1318 (piod) access: read/write ? linex [x=0..31]: dr ive of pio line x 31 30 29 28 27 26 25 24 line31 line30 line29 line28 line27 line26 line25 line24 23 22 21 20 19 18 17 16 line23 line22 line21 line20 line19 line18 line17 line16 15 14 13 12 11 10 9 8 line15 line14 line13 line12 line11 line10 line9 line8 76543210 line7 line6 line5 line4 line3 line2 line1 line0 value name description 0 low_drive lowest drive 1 high_drive highest drive
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 680 33. serial peripheral interface (spi) 33.1 description the serial peripheral interface (spi) circuit is a sync hronous serial data link that provides communication with external devices in master or slave mode. it also enables communication between processors if an external processor is connected to the system. the serial peripheral interface is essentially a shift register that serially transmits data bits to other spis. during a data transfer, one spi system acts as the ?master?' which controls the data flow, while the other devices act as ?slaves'' which have data shifted into and out by the mast er. different cpus can take turn being masters (multiple master protocol, contrary to single master protocol wher e one cpu is always the master while all of the others are always slaves). one master can simultaneously shift data into multiple slaves. howeve r, only one slave can drive its output to write data back to the master at any given time. a slave device is selected when the master asserts its nss signal. if multiple slave devices exist, the master generates a separate slave select signal for each slave (npcs). the spi system consists of two data lines and two control lines: ? master out slave in (mosi)?this data line supplies the output data from the master shifted into the input(s) of the slave(s). ? master in slave out (miso)?this data line supplies the ou tput data from a slave to the input of the master. there may be no more than one slave transmitting data during any particular transfer. ? serial clock (spck)?this control line is driven by the master and regulates the flow of the data bits. the master can transmit data at a variety of baud rates; t here is one spck pulse for each bit that is transmitted. ? slave select (nss)?this control line allows sl aves to be turned on and off by hardware.
681 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 33.2 embedded characteristics ? master or slave serial peripheral bus interface ? 8-bit to 16-bit programmable data length per chip select ? programmable phase and polarity per chip select ? programmable transfer delay between consecutive transfers and delay before spi clock per chip select ? programmable delay bet ween chip selects ? selectable mode fault detection ? master mode can drive spck up to peripheral clock ? master mode bit rate can be independ ent of the processor/peripheral clock ? slave mode operates on spck, asyn chronously with core and bus clock ? four chip selects with external decoder support allow communication with up to 15 peripherals ? communication with serial external devices supported ? serial memories, such as dataflash and 3-wire eeproms ? serial peripherals, such as adcs, dacs, lc d controllers, can cont rollers and sensors ? external coprocessors ? connection to pdc channel capabilit ies, optimizing data transfers ? one channel for the receiver ? one channel for the transmitter ? register write protection
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 682 33.3 block diagram 33.4 application block diagram figure 33-2. application block diagram: sing le master/multiple slave implementation figure 33-1. block diagram pdc spi peripheral bridge pmc peripheral clock bus clock ahb matrix trigger events spi master spck miso mosi npcs0 npcs1 npcs2 spck miso mosi nss slave 0 spck miso mosi nss slave 1 spck miso mosi nss slave 2 nc npcs3
683 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 33.5 signal description 33.6 product dependencies 33.6.1 i/o lines the pins used for interfacing the compliant external devices can be multiplexed with pio lines. the programmer must first program the pio controllers to assign the spi pins to their peripheral functions. 33.6.2 power management the spi can be clocked through the power management controller (pmc), thus the programmer must first configure the pmc to enable the spi clock. table 33-1. signal description pin name pin description type master slave miso master in slave out input output mosi master out slave in output input spck serial clock output input npcs1?npcs3 peripheral chip selects output unused npcs0/nss peripheral chip select/slave select output input table 33-2. i/o lines instance signal i/o line peripheral spi0 spi0_miso pa6 a spi0 spi0_mosi pa7 a spi0 spi0_npcs0 pa5 a spi0 spi0_npcs1 pa21 a spi0 spi0_npcs2 pa22 a spi0 spi0_npcs3 pa23 a spi0 spi0_spck pa8 a spi1 spi1_miso pc3 a spi1 spi1_mosi pc4 a spi1 spi1_npcs0 pc2 a spi1 spi1_npcs3 pc8 b spi1 spi1_spck pc5 a
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 684 33.6.3 interrupt the spi interface has an interrupt line connected to the interrupt controller. handling the spi interrupt requires programming the interrupt controller before configuring the spi. 33.6.4 peripheral dm a controller (pdc) the spi interface can be used in conj unction with the pdc in order to reduce processor overhead. for a full description of the pdc, refer to the co rresponding section in the full datasheet. 33.7 functional description 33.7.1 modes of operation the spi operates in master mode or in slave mode. ? the spi operates in master mode by writing a 1 to the mstr bit in the spi mode register (spi_mr): ? pins npcs0 to npcs3 are all configured as outputs ? the spck pin is driven ? the miso line is wired on the receiver input ? the mosi line is driven as an output by the transmitter. ? the spi operates in slave mode if the ms tr bit in the spi_mr is written to 0: ? the miso line is driven by the transmitter output ? the mosi line is wired on the receiver input ? the spck pin is driven by the transmitter to synchronize the receiver. ? the npcs0 pin becomes an input, and is used as a slave select signal (nss) ? npcs1 to npcs3 are not driven and can be used for other purposes. the data transfers are identically programmable for both modes of operations. the baud rate generator is activated only in master mode. 33.7.2 data transfer four combinations of polarity and phas e are available for data transfers. the clock polarity is programmed with the cpol bit in the spi chip select regi ster (spi_csr). the clock phase is programmed with the ncpha bit. these two parameters determine the edges of the clock signal on which data is dr iven and sampled. each of the two parameters has two possible states, resulting in four poss ible combinations that are incompatible with one another. consequently, a master/slave pair must use the same pa rameter pair values to communicate. if multiple slaves are connected and require different configurations, the master must reconfigure itself each time it needs to communicate with a different slave. table 33-4 shows the four modes and corresponding parameter settings. table 33-3. peripheral ids instance id spi0 21 spi1 40
685 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 33-3 and figure 33-4 show examples of data transfers. figure 33-3. spi transfer format (ncpha = 1, 8 bits per transfer) table 33-4. spi bus protocol mode spi mode cpol ncpha shift spck edge capture spck edge spck inactive level 0 0 1 falling rising low 1 0 0 rising falling low 2 1 1 rising falling high 3 1 0 falling rising high 6 * spck (cpol = 0) spck (cpol = 1) mosi (from master) miso (from slave) nss (to slave) spck cycle (for reference) msb msb lsb lsb 6 6 5 5 4 4 3 3 2 2 1 1 * not defined. 12345 78 6
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 686 figure 33-4. spi transfer format (ncpha = 0, 8 bits per transfer) 33.7.3 master mode operations when configured in master mode, the spi operates on the clock generated by the internal programmable baud rate generator. it fully controls the data transfers to and from the slave(s) connected to the spi bus. the spi drives the chip select line to the slave and the serial clock signal (spck). the spi features two holding registers, the transmit data register (spi _tdr) and the receive data register (spi_rdr), and a single shift register. the holding r egisters maintain the data flow at a constant rate. after enabling the spi, a data transfer starts when the processor writes to the spi_tdr. the written data is immediately transferred in the shift register and the transfer on the spi bus starts. while the data in the shift register is shifted on the mosi line, the miso line is sampled and shifted in the shift register. data cannot be loaded in the spi_rdr without transmi tting data. if there is no data to transmit, dummy data can be used (spi_tdr filled with ones). when the spi_mr.wdrbt bit is set, new data cannot be transmitted if the spi_rdr has not been read. if receiving mode is not required, for example when communicating with a slave receiver only (such as an lcd), the receive status flags in th e spi status register (spi_sr) can be discarded. before writing the spi_tdr, the pcs field in the spi_mr must be set in order to select a slave. if new data is written in the spi_tdr during the transfer, it is kept in the spi_tdr until the current transfer is completed. then, the received data is transferred from t he shift register to the spi_ rdr, the data in the spi_tdr is loaded in the shift register and a new transfer starts. the transfer of data written in the spi_tdr to the shift re gister is indicated by the transmit data register empty (tdre) bit in the spi_sr. when new data is written in the spi_tdr, this bit is cleared. the tdre bit is used to trigger the transmit pdc channel. the end of transfer is indicated by the txempty flag in the spi_sr. if a transfer delay (dlybct) is greater than 0 for the last transfer, txempty is set after the completion of this delay. th e peripheral clock can be switched off at this time. the transfer of received data from the sh ift register to the spi_rdr is indica ted by the receive data register full (rdrf) bit in the spi_sr. when the received data is read, the rdrf bit is cleared. spck (cpol = 0) spck (cpol = 1) 1 2345 7 mosi (from master) miso (from slave) nss (to slave) spck cycle (for reference) 8 msb msb lsb lsb 6 6 5 5 4 4 3 3 1 1 * not defined. 2 2 6 *
687 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 if the spi_rdr has not been read before new data is rece ived, the overrun error (ovres) bit in the spi_sr is set. as long as this flag is set, data is loaded in the spi_rdr. the user has to read the spi_sr to clear the ovres bit. figure 33-5 , shows a block diagram of the spi when operating in master mode. figure 33-6 on page 688 shows a flow chart describing how transfers are handled. 33.7.3.1 master mode block diagram figure 33-5. master mode block diagram shift register spck mosi lsb msb miso spi_rdr rd spi clock tdre spi_tdr td rdrf ovres spi_csrx cpol ncpha bits peripheral clock baud rate generator spi_csrx scbr npcsx npcs0 npcs0 0 1 ps spi_mr pcs spi_tdr pcs modf current peripheral spi_rdr pcs spi_csrx csaat pcsdec modfdis mstr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 688 33.7.3.2 master mode flow diagram figure 33-6. master mode flow diagram spi enable csaat ? ps ? 1 0 0 1 1 npcs = spi_tdr(pcs) npcs = spi_mr(pcs) delay dlybs serializer = spi_tdr(td) tdre = 1 data transfer spi_rdr(rd) = serializer rdrf = 1 tdre ? npcs deasserted delay dlybcs fixed peripheral variable peripheral delay dlybct 0 1 csaat ? 0 tdre ? 1 0 ps ? 0 1 spi_tdr(pcs) = npcs ? no yes spi_mr(pcs) = npcs ? no npcs deasserted delay dlybcs npcs = spi_tdr(pcs) npcs deasserted delay dlybcs npcs = spi_mr(pcs), spi_tdr(pcs) fixed peripheral variable peripheral - npcs defines the current chip select - csaat, dlybs, dlybct refer to the fields of the chip select register corresponding to the current chip select
689 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 33-7 shows the behavior of transmit data register empty (tdre), receive data register (rdrf) and transmission register empty (txempty) status flags within the spi_sr during an 8-bit data transfer in fixed mode without the pdc involved. figure 33-7. status register flags behavior 6 spck mosi (from master) miso (from slave) npcs0 msb msb lsb lsb 6 6 5 5 4 4 3 3 2 2 1 1 1 2345 78 6 rdrf tdre txempty write in spi_tdr rdr read shift register empty
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 690 figure 33-8 shows the behavior of transmission register em pty (txempty), end of rx buffer (endrx), end of tx buffer (endtx), rx buffer full (rxbuff) and tx buffer empty (txbufe) status flags within the spi_sr during an 8-bit data transfer in fixed mode with the pdc involved. the pdc is programmed to transfer and receive three units of data. the next pointer and counter are no t used. the rdrf and tdre are not shown because these flags are managed by the pdc when using the pdc. figure 33-8. pdc status register flags behavior 33.7.3.3 clock generation the spi baud rate clock is generated by dividing the peripheral clock by a value between 1 and 255. if the scbr field in the spi_csr is programmed to 1, the operating baud rate is peripheral clock (see the electrical characteristics se ction for the spck maximum frequency). trigge ring a transfer while scbr is at 0 can lead to unpredictable results. at reset, scbr is 0 and the user has to program it to a valid value before performing the first transfer. the divisor can be defined independently for each chip sele ct, as it has to be programmed in the scbr field. this allows the spi to automatically adapt the baud rate for each interfaced peripheral without reprogramming. 33.7.3.4 transfer delays figure 33-9 shows a chip select transfer change and consecutive transfers on the same chip select. three delays can be programmed to modify the transfer waveforms: ? delay between the chip selects?programmable only once for all chip selects by writing the dlybcs field in the spi_mr. the spi slave device deac tivation delay is managed through dlybcs. if there is only one spi slave device connected to the master, the dlybcs field does not need to be configured. if several slave devices are connected to a master, dlybcs must be configured depending on the highest deactivation delay. refer to the spi slave device electrical characteristics. ? delay before spck?independently programmable for each chip select by writing the dlybs field. the spi slave device activation delay is managed through dlybs. re fer to the spi slave device electrical characteristics to define dlybs. 654321 spck mosi (from master) npcs0 msb lsb 654321 12 3 endtx txempty msb lsb 654321 654321 miso (from slave) 654321 654321 endrx txbufe rxbuff tdre (not required if pdc is used) pdc loads first byte pdc loads 2nd byte (double buffer effect) pdc loads last byte msb msb msb msb lsb lsb lsb lsb
691 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? delay between consecutive transfer s?independently programmable for each chip select by writing the dlybct field. the time required by the spi slave de vice to process received data is managed through dlybct. this time depends on the spi slave system activity. these delays allow the spi to be adapted to the interfac ed peripherals and their speed and bus release time. figure 33-9. programmable delays 33.7.3.5 peripheral selection the serial peripherals are selected through the assert ion of the npcs0 to npcs3 signals. by default, all npcs signals are high before and after each transfer. ? fixed peripheral select mode : spi exchanges data with only one peripheral. fixed peripheral select mode is enabled by writing the ps bit to zero in the spi_mr. in this case, the current peripheral is defined by the pcs field in the spi_mr and the pcs field in the spi_tdr has no effect. ? variable peripheral select mode: data can be exchanged with more than one peripheral without having to reprogram the npcs field in the spi_mr. variable peripheral select mode is enabled by settin g the ps bit to 1 in the spi_mr. the pcs field in the spi_tdr is used to select the current peripheral. this means that the peripheral selection can be defined for each new data. the value to write in the spi_tdr has the following format: [xxxxxxx(7-bit) + lastxfer(1-bit) (1) + xxxx(4-bit) + pcs (4-bit) + data (8 to 16-bit)] with pcs equals the chip select to assert, as defined in section 33.8.4 ?spi transmit data register? and lastxfer bit at 0 or 1 depending on the csaat bit. note: 1. optional csaat, lastxfer and csnaat bits are discussed in section 33.7.3.9 ?peripheral deselection with pdc? . if lastxfer is used, the command must be issued before writing the last character. instead of lastxfer, the user can use the spidis command. after the end of the pdc transfer, it is necessary to wait for the txempty flag and then write spidis in to the spi control register (spi_cr). this does not change the configuration register values). the npcs is disabled after the last character transfer. then, another pdc transfer can be started if the spien has previously been written in the spi_cr. 33.7.3.6 spi peripheral dma controller (pdc) in both fixed and variable periphera l select modes, the peripheral dma c ontroller (pdc) can be used to reduce processor overhead. the fixed peripheral selection allows bu ffer transfers with a single peripheral . using the pdc is an optimal means, as the size of the data transfer between the memory and the spi is either 8 bits or 16 bits. however, if the peripheral selection is modified, the spi_mr must be reprogrammed. dlybcs dlybs dlybct dlybct chip select 1 chip select 2 spck
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 692 the variable peripheral selection allows buffer transfers with multiple peripherals without reprogramming the spi_mr. data written in the spi_tdr is 32 bits wide and defines the real data to be transmitted and the destination peripheral. using the pdc in this mode requires 32-bit wide buffers, with the data in the lsbs and the pcs and lastxfer fields in the msbs. however, the spi still controls the number of bits (8 to16) to be transferred through miso and mosi lines with the chip sele ct configuration registers ( spi_csrx). this is not the optimal means in terms of memory si ze for the buffers, but it provides a very effective m eans to exchange data with several peripherals without any intervention of the processor. transfer size depending on the data size to transmit, from 8 to 16 bi ts, the pdc manages automatically the type of pointer size it has to point to. the pdc performs the following transfer, depending on the mode and number of bits per data. ? fixed mode: ? 8-bit data: 1-byte transfer, pdc pointer address = address + 1 byte, pdc counter = counter - 1 ? 9-bit to 16-bit data: 2-byte transfer. n-bit data transfer with don?t care data (msb) filled with 0?s, pdc pointer address = address + 2 bytes, pdc counter = counter - 1 ? variable mode: ? in variable mode, pdc pointer address = address +4 bytes and pdc counter = counter - 1 for 8 to 16- bit transfer size. ? when using the pdc, the tdre and rdrf flags ar e handled by the pdc. the user?s application does not have to check these bits. only end of rx buffer (endrx), end of tx buffer (endtx), buffer full (rxbuff), tx buffer empty (txbufe) are significant. for further details about the peripheral dma controller and user interface, refer to the pdc section of the product datasheet. 33.7.3.7 peripheral chip select decoding the user can program the spi to operate with up to 15 sl ave peripherals by decoding th e four chip select lines, npcs0 to npcs3 with an external decoder/demultiplexer (refer to figure 33-10 ). this can be enabled by writing a 1 to the pcsdec bit in the spi_mr. when operating without decoding, the spi makes sure that in any case only one chip select line is activated, i.e., one npcs line driven low at a time. if two bits are defined low in a pcs field, only the lowest numbered chip select is driven low. when operating with decoding, the spi directly outputs the value defined by the pcs field on the npcs lines of either spi_mr or spi_tdr (depending on ps). as the spi sets a default value of 0xf on the chip select lines (i.e., all chip select lines at 1) when not processing any transfer, only 15 peripherals can be decoded. the spi has four chip select registers. as a result, w hen external decoding is activated, each npcs chip select defines the characteristics of up to four peripherals. as an example, spi_crs0 defines the characteristics of the externally decoded peripherals 0 to 3, corresponding to the pcs values 0x0 to 0x3. consequently, the user has to make sure to connect compatible peripherals on the decoded chip select lines 0 to 3, 4 to 7, 8 to 11 and 12 to 14. figure 33-10 shows this type of implementation. if the csaat bit is used, with or without the pdc, the m ode fault detection for npcs0 line must be disabled. this is not required for all other ch ip select lines since mode fa ult detection is only on npcs0.
693 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 33-10. chip select decoding application block diagram: single master/multiple slave implementation 33.7.3.8 peripheral d eselection without pdc during a transfer of more than one unit of data on a chip select without the pdc, the spi_tdr is loaded by the processor, the tdre flag rises as soon as the content of the spi_tdr is transfer red into the intern al shift register. when this flag is detected high, the spi_tdr can be reloaded. if this reload by the processor occurs before the end of the current transfer and if the next transfer is perfo rmed on the same chip select as the current transfer, the chip select is not de-asserted between the two transfers. but depending on the application software handling the spi status register flags (by interrupt or polling method) or servicing other interrupts or other tasks, the processor may not reload the spi_tdr in time to keep the chip select active (low). a null dlybct value (delay between consecutive transfers) in the spi_csr, gives even less ti me for the processor to reload the spi_tdr. with some spi slave peripherals, if the chip select line must remain active (low) during a full set of transfers, communication errors can occur. to facilitate interfacing with such devices, the chip se lect registers [csr0...csr3] can be programmed with the chip select active after transf er (csaat) bit to 1. this allo ws the chip select lines to remain in their current state (low = active) until a transfer to another chip select is re quired. even if the spi_tdr is not reloaded, the chip select remains active. to de-assert the chip select line at the end of the transfer, the last transfer (lastxfer) bit in the spi_mr must be set to 1 before writing the last data to transmit into the spi_tdr. 33.7.3.9 peripheral deselection with pdc pdc provides faster reloads of the spi_tdr compared to software. however, depending on the system activity, it is not guaranteed that the spi_tdr is written with the next data before the end of the current transfer. consequently, data can be lost by the de-assertion of th e npcs line for spi slave peripherals requiring the chip select line to remain active between two transfers. the only way to guarantee a safe transfer in this case is the use of the csaat and lastxfer bits. when the csaat bit is configured to 0, the npcs does not rise in all ca ses between two tran sfers on the same peripheral. during a transfer on a chip select, the tdre flag rises as soon as the content of the spi_tdr is transferred into the internal shift register. when this flag is detected, the spi_tdr can be reloaded. if this reload occurs before the end of the current transfer and if the next transfer is performed on the same chip select as the current transfer, the chip select is not de-asserted bet ween the two transfers. this can lead to difficulties to interface with some serial peripherals requiring the chip select to be de-asserted after each transfer. to facilitate spi master spck miso mosi npcs0 npcs1 npcs2 spck miso mosi nss slave 0 spck miso mosi nss slave 1 spck miso mosi nss slave 14 npcs3 decoded chip select lines external 1-of-n decoder/demultiplexer
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 694 interfacing with such devices, the spi_csr can be programmed with the chip select not active after transfer (csnaat) bit to 1. this allows the ch ip select lines to be de-asserted systematically during a time ?dlybcs? (the value of the csnaat bit is processe d only if the csaat bit is configured to 0 for the sa me chip select). figure 33-11 shows different peripheral deselection cases and the effect of the csaat and csnaat bits. figure 33-11. peripheral deselection 33.7.3.10mode fault detection the spi has the capability to operate in multi-master environment. consequently, the npcs0/nss line must be monitored. if one of the masters on the spi bus is curr ently transmitting, the npcs 0/nss line is low and the spi must not transmit any data. a mode fa ult is detected when the spi is progr ammed in master mode and a low level a npcs[0..n] write spi_tdr tdre npcs[0..n] write spi_tdr tdre npcs[0..n] write spi_tdr tdre dlybcs pcs = a dlybcs dlybct a pcs = b b dlybcs pcs = a dlybcs dlybct a pcs = b b dlybcs dlybct pcs=a a dlybcs dlybct a pcs = a a a dlybct aa csaat = 0 and csnaat = 0 dlybct aa csaat = 1 and csnaat= 0 / 1 a dlybcs pcs = a dlybct aa csaat = 0 and csnaat = 1 npcs[0..n] write spi_tdr tdre pcs = a dlybct aa csaat = 0 and csnaat = 0
695 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 is driven by an external master on the npcs0/nss sign al. in multi-master environm ent, npcs0, mosi, miso and spck pins must be configured in open drain (through the pio controller). when a mode fault is detected, the spi_sr.modf bit is set until spi_sr is read and the spi is automatically disabled until it is re-enabled by writing a 1 to the spi_cr.spien bit. by default, the mode fault detection is enabled. the us er can disable it by setting the spi_mr.modfdis bit. 33.7.4 spi slave mode when operating in slave mode, the spi processes data bi ts on the clock provided on the spi clock pin (spck). the spi waits until nss goes active be fore receiving the serial clock from an external master. when nss falls, the clock is validated and the data is loaded in the spi_rdr depending on the bits field configured in the spi_csr0. these bits are processed following a phase and a polarity defined respectively by the ncpha and cpol bits in the spi_csr0. note that bits, cpol and ncpha of the ot her chip select registers have no effect when the spi is programmed in slave mode. the bits are shifted out on the miso line and sampled on the mosi line. note: for more information on the bits field, see also the note below the spi_csrx register bitmap ( section 33.8.9 ?spi chip select register? ). when all bits are processed, the received data is tr ansferred in the spi_rdr and the rdrf bit rises. if the spi_rdr has not been read before new data is received, the overrun error status (o vres) bit in the spi_sr is set. as long as this flag is set, data is loaded in the spi_rdr. the user must read spi_sr to clear the ovres bit. when a transfer starts, the data shifted out is the data present in the shi ft register. if no data has been written in the spi_tdr, the last data received is transferred. if no data has been received since the last reset, all bits are transmitted low, as the shift register resets to 0. when a first data is written in the spi_tdr, it is transferred immediately in the shif t register and the tdre flag rises. if new data is written, it rema ins in the spi_tdr until a transfer occurs, i.e., nss falls and there is a valid clock on the spck pin. when the transfer occurs, the last data written in the spi_tdr is transferred in the shift register and the tdre flag rises. this enables frequent updates of critical variables with single transfers. then, new data is loaded in the shift register from the spi _tdr. if no character is read y to be transmitted, i.e., no character has been written in the spi_tdr since the last load from the spi_tdr to the shift register, the spi_tdr is retransmitted. in this case the underr un error status flag (undes) is set in the spi_sr. figure 33-12 shows a block diagram of the spi when operating in slave mode. figure 33-12. slave mode functional block diagram shift register spck spiens lsb msb nss mosi spi_rdr rd spi clock tdre spi_tdr td rdrf ovres spi_csr0 cpol ncpha bits spien spidis miso
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 696 33.7.5 register write protection to prevent any single software error from corrupting spi behavior, certain registers in the address space can be write-protected by settin g the wpen bit in the spi write protection mode register (spi_wpmr).
697 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 if a write access to a write-protected register is detected, the wpvs flag in the spi write protection status register (spi_wpsr) is set and the wpvsrc field indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after re ading spi_wpsr. the following registers can be write-protected: ? spi mode register ? spi chip select register
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 698 33.8 serial peripheral interf ace (spi) user interface table 33-5. register mapping offset register name access reset 0x00 control register spi_cr write-only ? 0x04 mode register spi_mr read/write 0x0 0x08 receive data register spi_rdr read-only 0x0 0x0c transmit data register spi_tdr write-only ? 0x10 status register spi_sr read-only 0x000000f0 0x14 interrupt enable register spi_ier write-only ? 0x18 interrupt disable register spi_idr write-only ? 0x1c interrupt mask register spi_imr read-only 0x0 0x20?0x2c reserved ? ? ? 0x30 chip select register 0 spi_csr0 read/write 0x0 0x34 chip select register 1 spi_csr1 read/write 0x0 0x38 chip select register 2 spi_csr2 read/write 0x0 0x3c chip select register 3 spi_csr3 read/write 0x0 0x40?0xe0 reserved ? ? ? 0xe4 write protection mode re gister spi_wpmr read/write 0x0 0xe8 write protection status register spi_wpsr read-only 0x0 0xec?0xf8 reserved ? ? ? 0xfc reserved ? ? ? 0x100?0x124 reserved for pdc registers ? ? ?
699 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 33.8.1 spi control register name: spi_cr address: 0x40008000 (0), 0x48000000 (1) access: write-only ? spien: spi enable 0: no effect. 1: enables the spi to transfer and receive data. ? spidis: spi disable 0: no effect. 1: disables the spi. as soon as spidis is set, spi finishes its transfer. all pins are set in input mode and no data is received or transmitted. if a transfer is in progress, the transfer is finished before the spi is disabled. if both spien and spidis are equal to one when the spi_cr is written, the spi is disabled. ? swrst: spi software reset 0: no effect. 1: reset the spi. a software-triggered hardware reset of the spi interface is performed. the spi is in slave mode after software reset. pdc channels are not affected by software reset. ? lastxfer: last transfer 0: no effect. 1: the current npcs is de-asse rted after the characte r written in td has been transferred. when spi_csrx.csaat is set, the communication with the current serial peripheral can be clos ed by raising the corresponding npcs line as soon as td transfer is completed. refer to section 33.7.3.5 ?p eripheral selection? for more details. 31 30 29 28 27 26 25 24 ???????l a s t x f e r 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 s w r s t?????s p i d i ss p i e n
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 700 33.8.2 spi mode register name: spi_mr address: 0x40008004 (0), 0x48000004 (1) access: read/write this register can only be written if the wpen bit is cleared in the spi write protection mode register . ? mstr: master/slave mode 0: spi is in slave mode 1: spi is in master mode ? ps: peripheral select 0: fixed peripheral select 1: variable peripheral select ? pcsdec: chip select decode 0: the chip selects are directly connected to a peripheral device. 1: the four npcs chip select lines are connected to a 4-bit to 16-bit decoder. when pcsdec = 1, up to 15 chip select signals can be gener ated with the four npcs lines us ing an external 4-bit to 16- bit decoder. the chip select registers define the characteristics of the 15 chip selects, with the following rules: spi_csr0 defines peripheral chip select signals 0 to 3. spi_csr1 defines peripheral chip select signals 4 to 7. spi_csr2 defines peripheral chip select signals 8 to 11. spi_csr3 defines peripheral chip select signals 12 to 14. ? modfdis: mode fault detection 0: mode fault detection enabled 1: mode fault detection disabled ? wdrbt: wait data read before transfer 0: no effect. in master mode, a transfer c an be initiated regardless of the spi_rdr state. 1: in master mode, a transfer can start only if the spi_rdr is empty, i.e., does not contain any unread data. this mode prevents overrun error in reception. ? llb: local loopback enable 0: local loopback path disabled. 31 30 29 28 27 26 25 24 dlybcs 23 22 21 20 19 18 17 16 ???? p c s 15 14 13 12 11 10 9 8 ???????? 76543210 llb ? wdrbt modfdis ? pcsdec ps mstr
701 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1: local loopback path enabled. llb controls the local loopback on the data shift register for testing in master mode only (miso is internally connected on mosi). ? pcs: peripheral chip select this field is only used if fixed pe ripheral select is active (ps = 0). if spi_mr.pcsdec = 0: pcs = xxx0 npcs[3:0] = 1110 pcs = xx01 npcs[3:0] = 1101 pcs = x011 npcs[3:0] = 1011 pcs = 0111 npcs[3:0] = 0111 pcs = 1111 forbidden (no peripheral is selected) (x = don?t care) if spi_mr.pcsdec = 1: npcs[3:0] output signals = pcs. ? dlybcs: delay between chip selects this field defines the delay between the inactivation and th e activation of npcs. the dlybc s time guarantees non-over- lapping chip selects and solves bu s contentions in case of peripherals having long data float times. if dlybcs is lower than 6, six periphera l clock periods are inserted by default. otherwise, the following equation determines the delay: : delay between chip selects dlybcs f peripheral clock -------------------------------- - =
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 702 33.8.3 spi receive data register name: spi_rdr address: 0x40008008 (0), 0x48000008 (1) access: read-only ? rd: receive data data received by the spi interface is st ored in this register in a right-justif ied format. unused bits are read as zero. ? pcs: peripheral chip select in master mode only, these bits indicate the value on the npcs pins at the end of a transfer. otherwise, these bits are read as zero. note: when using variable peripheral select mode (ps = 1 in spi_mr) , it is mandatory to set the spi_mr.wdrbt bit to 1 if the pcs field must be processed in spi_rdr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???? p c s 15 14 13 12 11 10 9 8 rd 76543210 rd
703 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 33.8.4 spi transmit data register name: spi_tdr address: 0x4000800c (0), 0x4800000c (1) access: write-only ? td: transmit data data to be transmitted by the spi interface is stored in this register. information to be tran smitted must be written to the transmit data register in a right-justified format. ? pcs: peripheral chip select this field is only used if variable pe ripheral select is active (ps = 1). if spi_mr.pcsdec = 0: pcs = xxx0 npcs[3:0] = 1110 pcs = xx01 npcs[3:0] = 1101 pcs = x011 npcs[3:0] = 1011 pcs = 0111 npcs[3:0] = 0111 pcs = 1111 forbidden (no peripheral is selected) (x = don?t care) if spi_mr.pcsdec = 1: npcs[3:0] output signals = pcs. ? lastxfer: last transfer 0: no effect 1: the current npcs is de-asserted afte r the transfer of the charac ter written in td. when spi_csrx.csaat is set, the communication with the current serial peripheral can be closed by raising the corresponding npcs line as soon as td transfer is completed. this field is only used if variable perip heral select is active (spi_mr.ps = 1). 31 30 29 28 27 26 25 24 ???????l a s t x f e r 23 22 21 20 19 18 17 16 ???? p c s 15 14 13 12 11 10 9 8 td 76543210 td
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 704 33.8.5 spi status register name: spi_sr address: 0x40008010 (0), 0x48000010 (1) access: read-only ? rdrf: receive data register full (automatically set / cleared) 0: no data has been received since the last read of spi_rdr. 1: data has been received and the received data has been transf erred from the shift register to spi_rdr since the last read of spi_rdr. ? tdre: transmit data register empty (automatically set / cleared) 0: data has been written to spi_tdr and not yet transferred to the shift register. 1: the last data written in the spi_tdr ha s been transferred to the shift register. tdre equals zero when the spi is disabled or at reset. the spi enable command sets this bit to 1. ? modf: mode fault error (cleared on read) 0: no mode fault has been detected since the last read of spi_sr. 1: a mode fault occurred since the last read of spi_sr. ? ovres: overrun error status (cleared on read) 0: no overrun has been detected since the last read of spi_sr. 1: an overrun has occurred since the last read of spi_sr. an overrun occurs when spi_rdr is loaded at least twice fr om the shift register since the last read of the spi_rdr. ? endrx: end of rx buffer (automatically set / cleared) 0: the receive counter register has not reached 0 since the last write in spi_rcr (1) or spi_rncr (1) . 1: the receive counter register has re ached 0 since the last write in spi_rcr (1) or spi_rncr (1) . ? endtx: end of tx buffer (automatically set / cleared) 0: the transmit counter register has not reached 0 since the last write in spi_tcr (1) or spi_tncr (1) . 1: the transmit counter register has reached 0 since the last write in spi_tcr (1) or spi_tncr (1) . ? rxbuff: rx buffer full (a utomatically set / cleared) 0: spi_rcr (1) or spi_rncr (1) has a value other than 0. 1: both spi_rcr (1) and spi_rncr (1) have a value of 0. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????s p i e n s 15 14 13 12 11 10 9 8 ????? undes txempty nssr 76543210 txbufe rxbuff endtx endrx ovres modf tdre rdrf
705 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? txbufe: tx buffer empty (automatically set / cleared) 0: spi_tcr (1) or spi_tncr (1) has a value other than 0. 1: both spi_tcr (1) and spi_tncr (1) have a value of 0. ? nssr: nss rising (cleared on read) 0: no rising edge detected on nss pin since the last read of spi_sr. 1: a rising edge occurred on nss pi n since the last read of spi_sr. ? txempty: transmission registers empty (automatically set / cleared) 0: as soon as data is written in spi_tdr. 1: spi_tdr and internal shift register are empty. if a transfer delay has been defined, txempty is set after the end of this delay. ? undes: underrun error status (slave mode only) (cleared on read) 0: no underrun has been detected since the last read of spi_sr. 1: a transfer starts whereas no data has been loaded in spi_tdr. ? spiens: spi enable status 0: spi is disabled. 1: spi is enabled. note: 1. spi_rcr, spi_rncr, spi_tcr, spi_tncr are pdc registers.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 706 33.8.6 spi interrupt enable register name: spi_ier address: 0x40008014 (0), 0x48000014 (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? rdrf: receive data register full interrupt enable ? tdre: spi transmit data re gister empty interrupt enable ? modf: mode fault error interrupt enable ? ovres: overrun error interrupt enable ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? rxbuff: receive buffer full interrupt enable ? txbufe: transmit buffer empty interrupt enable ? nssr: nss rising interrupt enable ? txempty: transmission registers empty enable ? undes: underrun error interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????? undes txempty nssr 76543210 txbufe rxbuff endtx endrx ovres modf tdre rdrf
707 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 33.8.7 spi interrupt disable register name: spi_idr address: 0x40008018 (0), 0x48000018 (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? rdrf: receive data register full interrupt disable ? tdre: spi transmit data re gister empty interrupt disable ? modf: mode fault error interrupt disable ? ovres: overrun error interrupt disable ? endrx: end of receive buffer interrupt disable ? endtx: end of transmit buffer interrupt disable ? rxbuff: receive buffer full interrupt disable ? txbufe: transmit buffer empty interrupt disable ? nssr: nss rising interrupt disable ? txempty: transmission registers empty disable ? undes: underrun erro r interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????? undes txempty nssr 76543210 txbufe rxbuff endtx endrx ovres modf tdre rdrf
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 708 33.8.8 spi interrupt mask register name: spi_imr address: 0x4000801c (0), 0x4800001c (1) access: read-only the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. ? rdrf: receive data register full interrupt mask ? tdre: spi transmit data re gister empty interrupt mask ? modf: mode fault error interrupt mask ? ovres: overrun error interrupt mask ? endrx: end of receive buffer interrupt mask ? endtx: end of transmit buffer interrupt mask ? rxbuff: receive buffer full interrupt mask ? txbufe: transmit buff er empty interrupt mask ? nssr: nss rising interrupt mask ? txempty: transmission registers empty mask ? undes: underrun error interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????? undes txempty nssr 76543210 txbufe rxbuff endtx endrx ovres modf tdre rdrf
709 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 33.8.9 spi chip select register name: spi_csrx[x=0..3] address: 0x40008030 (0), 0x48000030 (1) access: read/write this register can only be written if the wpen bit is cleared in the spi write protection mode register . note: spi_csrx registers must be written even if the user wants to use the default reset values. the bits field is not updated w ith the translated value unless the register is written. ? cpol: clock polarity 0: the inactive state value of spck is logic level zero. 1: the inactive state value of spck is logic level one. cpol is used to determine the inactive state value of the serial clock (spck). it is used with ncpha to produce the required clock/data relationship be tween master and slave devices. ? ncpha: clock phase 0: data is changed on the leading edge of sp ck and captured on the following edge of spck. 1: data is captured on the leading edge of spck and changed on the following edge of spck. ncpha determines which edge of spck causes data to chang e and which edge causes data to be captured. ncpha is used with cpol to produce the required clock/data relationship between master and slave devices. ? csnaat: chip select not active after transfer (ignored if csaat = 1) 0: the peripheral chip select does not rise between two tran sfers if the spi_tdr is reload ed before the end of the first transfer and if the two transfers occur on the same chip select. 1: the peripheral chip select rises syst ematically after each transfer performed on the same slave. it remains inactive after the end of transfer for a minimal duration of: ? csaat: chip select active after transfer 0: the peripheral chip select line rises as soon as the last transfer is achieved. 1: the peripheral chip select does not rise after the last tr ansfer is achieved. it remains active until a new transfer is requested on a different chip select. ? bits: bits per transfer (see the note below the register bitmap.) 31 30 29 28 27 26 25 24 dlybct 23 22 21 20 19 18 17 16 dlybs 15 14 13 12 11 10 9 8 scbr 76543210 bits csaat csnaat ncpha cpol (if field dlybcs is lower than 6, a minimum of six periods is introduced.) dlybcs f peripheral clock -------------------------------- -
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 710 the bits field determines the number of data bits transferred. rese rved values should not be used. ? scbr: serial clock baud rate in master mode, the spi interface uses a modulus counter to derive the spck baud rate from the peripheral clock. the baud rate is selected by writing a value from1 to 255 in th e scbr field. the following e quation determines the spck baud rate: : do not program the scbr field to 0. triggering a transfer while scbr is at 0 can lead to unpredictable results. at reset, scbr is 0 and the user has to program it at a valid value before performing the first transfer. note: if one of the scbr fields in spi_csrx is set to 1, the other scbr fields in spi_csrx must be set to 1 as well, if they are used to process transfers. if they are not used to tr ansfer data, they can be set at any value. ? dlybs: delay before spck this field defines the delay from npcs falling edge (activation) to the first valid spck transition. when dlybs equals zero, the delay is half the spck clock period. otherwise, the following equation determines the delay: ? dlybct: delay between consecutive transfers this field defines the delay between two consecutive transfers with the same perip heral without removing the chip select. the delay is always inserted after each transfer and before removing the chip select if needed. value name description 0 8_bit 8 bits for transfer 1 9_bit 9 bits for transfer 2 10_bit 10 bits for transfer 3 11_bit 11 bits for transfer 4 12_bit 12 bits for transfer 5 13_bit 13 bits for transfer 6 14_bit 14 bits for transfer 7 15_bit 15 bits for transfer 8 16_bit 16 bits for transfer 9? reserved 10 ? reserved 11 ? reserved 12 ? reserved 13 ? reserved 14 ? reserved 15 ? reserved spck baudrate f peripheral clock scbr -------------------------------- - = delay before spck dlybs f peripheral clock -------------------------------- - =
711 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 when dlybct equals zero, no delay between consecutive transfer s is inserted and the clock keeps its duty cycle over the character transfers. otherwise, the following equation determines the delay: delay between consecutive transfers 32 dlybct f peripheral clock ----------------------------------- - =
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 712 33.8.10 spi write protection mode register name: spi_wpmr address: 0x400080e4 (0), 0x480000e4 (1) access: read/write. ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x535049 (?spi? in ascii) 1: enables the write protection if wpkey corresponds to 0x535049 (?spi? in ascii) see section 33.7.5 ?register write protection? for the list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x535049 passwd writing any other value in this field abort s the write operation of the wpen bit. always reads as 0.
713 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 33.8.11 spi write protection status register name: spi_wpsr address: 0x400080e8 (0), 0x480000e8 (1) access: read-only ? wpvs: write protection violation status 0: no write protection violation has occurred since the last read of spi_wpsr. 1: a write protection violation has occurred since the last read of spi_wpsr. if this violation is an unauthorized attempt to write a protected regi ster, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at whic h a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 714 34. two-wire interface (twi2) 34.1 description the atmel two-wire interface (twi2) interconnects components on a unique two-wire bus, made up of one clock line and one data line with speeds of up to 400 kbits pe r second, based on a byte-oriented transfer format. it can be used with any atmel two-wire interface bus serial eeprom and i2c compatible device such as a real time clock (rtc), dot matrix/graphic lcd controllers and temperature sensor. the twi is programmable as a master or a slave with sequential or single-byte acce ss. multiple master capability is supported. arbitration of the bus is performed internally and puts the twi in slave mode automatically if the bus arbitration is lost. a configurable baud rate generator permits the output data rate to be adapted to a wide range of core clock frequencies. table 34-1 lists the compatibility level of the atmel two-wire interface in master mode and a full i 2 c compatible device. note: start + b000000001 + ack + sr 34.2 embedded characteristics ? compatible with atmel two-wire interface se rial memory and i2c compatible devices (note:) ? one, two or three bytes for slave address ? sequential read/write operations ? master, multi-master and slave mode operation ? bit rate: up to 400 kbit/s ? general call supported in slave mode ? smbus quick command supported in master mode ? connection to peripheral dma controller (pdc) channel capabilities optimizes data transfers ? one channel for the receiver, one channel for the transmitter ? register write protection note: see table 34-1 for details on compatibility with i2c standard. table 34-1. atmel twi compatibility with i 2 c standard i 2 c standard atmel twi standard mode speed (100 khz) supported fast mode speed (400 khz) supported 7- or 10-bit slave addressing supported start byte not supported repeated start (sr) condition supported ack and nack management supported slope control and input filtering (fast mode) not supported clock stretching/synchronization supported multi master capability supported
715 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.3 list of abbreviations 34.4 block diagram figure 34-1. block diagram table 34-2. abbreviations abbreviation description twi two-wire interface a acknowledge na non acknowledge pstop sstart sr repeated start sadr slave address adr any address except sadr rread wwrite peripheral bridge pmc peripheral clock two-wire interface pio interrupt controller twi interrupt twck twd bus clock
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 716 34.5 application block diagram figure 34-2. application block diagram 34.5.1 i/o lines description 34.6 product dependencies 34.6.1 i/o lines both twd and twck are bidirectional lin es, connected to a positive supply voltage via a current source or pull-up resistor (see figure 34-2 ). when the bus is free, both lines are high. the output stages of dev ices connected to the bus must have an open-drain or open-colle ctor to perform the wired-and function. twd and twck pins may be multiplexed with pio lines . to enable the twi, the user must program the pio controller to dedicate twd and twck as peripheral lines. the user must not program twd and twck as open- drain. this is already done by the hardware. 34.6.2 power management the twi interface may be clocked through the power management controller (pmc), thus the user must first configure the pmc to enable the twi clock. host with twi interface twd twck atmel twi serial eeprom i2c rtc i2c lcd controller slave 1 slave 2 slave 3 v dd i2c temp. sensor slave 4 rp: pull-up value as given by the i2c standard rp rp table 34-3. i/o lines description pin name pin description type twd two-wire serial data input/output twck two-wire serial clock input/output table 34-4. i/o lines instance signal i/o line peripheral twi0 twck0 pa25 a twi0 twd0 pa24 a twi1 twck1 pb1 a twi1 twd1 pb0 a
717 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.6.3 interrupt the twi interface has an interrupt line connected to t he interrupt controller. in order to handle interrupts, the interrupt controller must be programmed before configuring the twi. 34.7 functional description 34.7.1 transfer format the data put on the twd line must be 8-bit long. data is transferred msb first; each byte must be followed by an acknowledgement. the number of bytes per transfer is unlimited (see figure 34-4 ). each transfer begins with a start conditi on and terminates with a stop condition (see figure 34-3 ). ? a high-to-low transition on the twd line while twck is high defines the start condition. ? a low-to-high transition on the twd line while twck is high defines the stop condition. figure 34-3. start and stop conditions figure 34-4. transfer format 34.7.2 modes of operation the twi has different modes of operations: ? master transmitter mode ? master receiver mode ? multi-master transmitter mode ? multi-master receiver mode ? slave transmitter mode ? slave receiver mode these modes are described in the following sections. table 34-5. peripheral ids instance id twi0 19 twi1 20 twd twck start stop twd twck start address r/w ack data ack data ack stop
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 718 34.7.3 master mode 34.7.3.1 definition the master is the device that starts a transfer, generates a clock and stops it. 34.7.3.2 application block diagram figure 34-5. master mode typical application block diagram 34.7.3.3 programming master mode the following fields must be programmed before entering master mode: 1. twi_mmr.dadr (+ iadrsz + iadr if a 10-bit device is addressed): the device address is used to access slave devices in read or write mode. 2. twi_cwgr.ckdiv + chdiv + cldiv: clock waveform. 3. twi_cr.svdis: disables the slave mode 4. twi_cr.msen: enables the master mode note: if the twi is already in master mode, the device address (dadr) can be configured without disabling the master mode. 34.7.3.4 master transmitter mode after the master initiates a start condition when writing in to the transmit holding regi ster (twi_thr), it sends a 7-bit slave address, configured in the master mode register (dadr in twi_mmr ), to notify the slave device. the bit following the slave address indicates the transfer direction?0 in this case (mread = 0 in twi_mmr). the twi transfers require the slave to acknowledge each received byte. during the acknowledge clock pulse (9th pulse), the master releases the data line (high), enabli ng the slave to pull it down in order to generate the acknowledge. the master polls the data line during this clock pulse and sets the not acknowledge bit (nack ) in the status register (twi_sr) if the slave does not acknowledge the byte. as with the other status bits, an interrupt can be generated if enabled in the interrupt enable register (twi_ier). if the slave acknowledges the byte, the data written in the twi_thr is then shifted in the internal shifter and transferred. when an acknowledge is detected, the txrdy bit is set un til a new write in the twi_thr. txrdy is used as transmit ready for the pdc transmit channel. while no new data is written in the twi_thr, the serial clock line is tied low. when new data is written in the twi_thr, the scl is released and the data is sent. settin g the stop bit in twi_cr generates a stop condition. after a master write transfer, the serial clock line is stre tched (tied low) as long as no new data is written in the twi_thr or until a stop command is performed. see figure 34-6 , figure 34-7 , and figure 34-8 . host with twi interface twd twck atmel twi serial eeprom i2c rtc i2c lcd controller slave 1 slave 2 slave 3 v dd i2c temp. sensor slave 4 rp: pull-up value as given by the i2c standard rp rp
719 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 34-6. master write with one data byte figure 34-7. master write with multiple data bytes txcomp txrdy write thr (data) stop command sent (write in twi_cr) twd adataa s dadr w p a data n a s dadr w data n+1 a p data n+2 a txcomp txrdy write thr (data n) write thr (data n+1) write thr (data n+2) last data sent stop command performed (by writing in the twi_cr) twd twck
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 720 figure 34-8. master write with one byte internal address and multiple data bytes 34.7.3.5 master receiver mode the read sequence begins by setting the start bit. af ter the start condition has been sent, the master sends a 7-bit slave address to notify the slave device. t he bit following the slave addr ess indicates the transfer direction?1 in this case (mread = 1 in twi_mmr). du ring the acknowledge clock pulse (9th pulse), the master releases the data line (high), enabling the slave to pull it down in order to generate the acknowledge. the master polls the data line during this clock pulse and sets the na ck bit in the twi_sr if the slave does not acknowledge the byte. if an acknowledge is received, the mast er is then ready to receive data from the slave. after data has been received, the master sends an acknowledge condition to notify the slave that the data has been received except for the last data. see figure 34-9 . when the rxrdy bit is set in the twi_sr, a character has been received in the receive holding register (twi_rhr). the rx rdy bit is reset when reading the twi_rhr. rxrdy is used as receive read y for the pdc receive channel. when a single data byte read is performed, with or wi thout internal address (iadr), the start and stop bits must be set at the same time. see figure 34-9 . when a multiple data byte r ead is performed, with or without internal address (iadr), the stop bit must be set after the next-to-la st data received. see figure 34-10 . for internal address usage, see section 34.7.3.6 . if the receive holding register (twi_r hr) is full (rxrdy high) and the master is receiving data, the serial clock line is tied low before receiving the last bit of the data and until the twi_rhr is read. once the twi_rhr is read, the master stops stretching the serial cl ock line and ends the data reception. see figure 34-11 . warning: when receiving multiple bytes in master read mode, if the next-to-last access is not read (the rxrdy flag remains high), th e last access is not completed until twi_rhr is read. the last access stops on the next-to- last bit. when the twi_rhr is read, the stop bit command must be sent within a period of half a bit only, otherwise another read access might occur (spurious access). a possible workaround is to set the stop bit before readi ng the twi_rhr on the next-to-last access (within the it handler). a data n a s dadr w data n+1 a p data n+2 a txcomp txrdy write thr (data n) write thr (data n+1) write thr (data n+2) last data sent stop command performed (by writing in the twi_cr) twd iadr a twck
721 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 34-9. master read with one data byte figure 34-10. master read wi th multiple data bytes figure 34-11. master read wait st ate with multiple data bytes 34.7.3.6 internal address the twi interface can perform transfers with 7-bit slav e address devices and 10-bit slave address devices. 7-bit slave addressing when addressing 7-bit slave devices, the internal addr ess bytes are used to perform random address (read or write) accesses to reach one or more data bytes, e.g. within a memory page location in a serial memory. when performing read operations with an internal address, the twi performs a write operation to set the internal address into the slave device, and then switch to master re ceiver mode. note that the second start condition (after a s dadr r data na p txcomp write start & stop bit rxrdy read rhr twd na a s dadr r data n a a data (n+1) a data (n+m) data (n+m)-1 p twd txcomp write start bit rxrdy write stop bit after next-to-last data read read rhr data n read rhr data (n+1) read rhr data (n+m)-1 read rhr data (n+m) adata na s dadr w data n+1 a p data n+2 a txcomp rxrdy read rhr (data n) stop command performed (by writing in the twi_cr) twd twck read rhr (data n+1) read rhr (data n+2) clock wait state
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 722 sending the iadr) is sometimes ca lled ?repeated start? (sr) in i 2 c fully-compatible devices. see figure 34-13 . see figure 34-12 and figure 34-14 for master write operat ion with internal address. the three internal address bytes are configurable through the master mode register (twi_mmr). if the slave device supports only a 7-bit address, i.e., no internal address, iadrsz must be set to 0. table 34-6 shows the abbreviations used in figure 34-12 and figure 34-13 . figure 34-12. master write with one, two or three bytes internal address and one data byte figure 34-13. master read with one, two or three bytes internal address and one data byte 10-bit slave addressing for a slave address higher than seven bits, the user must configure the address size ( iadrsz) and set the other slave address bits in the internal address register (twi_iadr). the two remaini ng internal address bytes, iadr[15:8] and iadr[23:16] can be used the same way as in 7-bit slave addressing. example: address a 10-bit device (10-bit device address is b1 b2 b3 b4 b5 b6 b7 b8 b9 b10) 1. program iadrsz = 1, 2. program dadr with 1 1 1 1 0 b1 b2 (b1 is the msb of the 10-bit address, b2, etc.) table 34-6. abbreviations abbreviation definition sstart sr repeated start pstop wwrite rread a acknowledge na not acknowledge dadr device address iadr internal address s dadr w a iadr(23:16) a iadr(15:8) a iadr(7:0) a data a p s dadr w a iadr(15:8) a iadr(7:0) a p data a a iadr(7:0) a p data a s dadr w twd three bytes internal address two bytes internal address one byte internal address twd twd s dadr w a iadr(23:16) a iadr(15:8) a iadr(7:0) a s dadr w a iadr(15:8) a iadr(7:0) a a iadr(7:0) a s dadr w data na p sr dadr r a sr dadr r a data na p sr dadr r a data na p twd twd twd three bytes internal address two bytes internal address one byte internal address
723 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 3. program twi_iadr with b3 b4 b5 b6 b7 b8 b9 b10 (b10 is the lsb of the 10-bit address) figure 34-14 below shows a byte write to an atmel at24lc512 eeprom. this demonstrates the use of internal addresses to access the device. figure 34-14. internal address usage 34.7.3.7 using the peripheral dma controller (pdc) the use of the pdc significantly reduces the cpu load. to ensure correct implementation, proceed as follows. data transmit with the pdc 1. initialize the transmit pdc (memor y pointers, transfer size - 1). 2. configure the master (dadr, ckdiv, mread = 0, etc.) 3. start the transfer by setting the pdc txten bit. 4. wait for the pdc endtx flag either by using the polling method or endtx interrupt. 5. disable the pdc by setting the pdc txtdis bit. 6. wait for the txrdy flag in twi_sr. 7. set the stop bit in twi_cr. 8. write the last character in twi_thr. 9. (optional) wait for the txcomp flag in twi_sr before disabling the peripheral clock if required. data receive with the pdc the pdc transfer size must be defined with the buffer si ze minus 2. the two rema ining characters must be managed without pdc to ensure that the exact number of bytes are received regardless of system bus latency conditions encountered during t he end of buffer transfer period. in slave mode, the number of characters to receive must be known in order to configure the pdc. 1. initialize the receive pdc (memor y pointers, transfer size - 2). 2. configure the master (dadr, ckdiv, mread = 1, etc.) 3. set the pdc rxten bit. 4. (master only) write the start bit in the twi_cr to start the transfer. 5. wait for the pdc endrx fl ag either by using polling method or endrx interrupt. 6. disable the pdc by setting the pdc rxtdis bit. 7. wait for the rxrdy flag in twi_sr. 8. set the stop bit in twi_cr. 9. read the penultimate character in twi_rhr. 10. wait for the rxrdy flag in twi_sr. 11. read the last character in twi_rhr. 12. (optional) wait for the txcomp flag in twi_sr before disabling the peripheral clock if required. s t a r t m s b device address 0 l s b r / w a c k m s b w r i t e a c k a c k l s b a c k first word address second word address data s t o p
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 724 34.7.3.8 smbus quick command (master mode only) the twi interface can perform a quick command: 1. configure the master mode (dadr, ckdiv, etc.). 2. write the mread bit in the twi_mmr at the value of the one-bit command to be sent. 3. start the transfer by setting the quick bit in the twi_cr. figure 34-15. smbus quick command 34.7.3.9 read/write flowcharts the flowcharts shown in figure 34-17 , figure 34-18 , figure 34-19 , figure 34-20 and figure 34-21 provide examples of read and write operations. a polling or inte rrupt method can be used to check the status bits. the interrupt method re quires that the interrupt enable r egister (twi_ier) be configured first. txcomp txrdy write quick command in twi_cr twd a s dadr r/w p
725 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 34-16. twi write operation with sing le data byte withou t internal address set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address (dadr) - transfer direction bit write ==> bit mread = 0 load transmit register twi_thr = data to send read status register txrdy = 1? read status register txcomp = 1? transfer finished yes yes begin no no write stop command twi_cr = stop
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 726 figure 34-17. twi write operation with single data byte and internal address begin set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address (dadr) - internal address size (iadrsz) - transfer direction bit write ==> bit mread = 0 load transmit register twi_thr = data to send read status register txrdy = 1? read status register txcomp = 1? transfer finished set the internal address twi_iadr = address yes yes no no write stop command twi_cr = stop
727 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 34-18. twi write operation with multiple data bytes with or without internal address set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address - internal address size (if iadr used) - transfer direction bit write ==> bit mread = 0 internal address size = 0? load transmit register twi_thr = data to send read status register txrdy = 1? data to send? read status register txcomp = 1? end begin set the internal address twi_iadr = address yes twi_thr = data to send yes yes yes no no no write stop command twi_cr = stop no set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 728 figure 34-19. twi read operation with sing le data byte without internal address set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address - transfer direction bit read ==> bit mread = 1 start the transfer twi_cr = start | stop read status register rxrdy = 1? read status register txcomp = 1? end begin yes yes set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) read receive holding register no no
729 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 34-20. twi read operation with single data byte and internal address set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address - internal address size (iadrsz) - transfer direction bit read ==> bit mread = 1 read status register txcomp = 1? end begin yes set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) yes set the internal address twi_iadr = address start the transfer twi_cr = start | stop read status register rxrdy = 1? read receive holding register no no
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 730 figure 34-21. twi read operation with multiple data bytes with or wi thout internal address internal address size = 0? start the transfer twi_cr = start stop the transfer twi_cr = stop read status register rxrdy = 1? last data to read but one? read status register txcomp = 1? end set the internal address twi_iadr = address yes yes yes no yes read receive holding register (twi_rhr) no set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address - internal address size (if iadr used) - transfer direction bit read ==> bit mread = 1 begin set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) no no read status register rxrdy = 1? yes read receive holding register (twi_rhr) no
731 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.7.4 multi-master mode 34.7.4.1 definition in multi-master mode, more than one master may handle th e bus at the same time without data corruption by using arbitration. arbitration starts as soon as two or more masters pl ace information on the bus at the same time, and stops (arbitration is lost) for the master t hat intends to send a logical one while the other master se nds a logical zero. as soon as a master lose arbitration, it stops sending data and listens to the bus in order to detect a stop. when the stop is detected, the master may put its data on the bus by performing arbitration. arbitration is illustrated in figure 34-23 . 34.7.4.2 two multi-master modes two multi-master modes may be distinguished: 1. twi is considered as a master only and will never be addressed. 2. twi may be either a master or a slave and may be addressed. note: arbitration is supported in both multi-master modes. twi as master only in this mode, twi is considered as a master only (msen is always one) and must be driven like a master with the arblst (arbitration lost) flag in addition. if arbitration is lost (arblst = 1), the user must reinitiate the data transfer. if the user starts a transfer (ex.: dadr + start + w + wr ite in thr) and if the bus is busy, the twi automatically waits for a stop condition on the bus to initiate the transfer (see figure 34-22 ). note: the state of the bus (busy or free) is not shown in the user interface. twi as master or slave the automatic reversal from master to slave is not supported in case of a lost arbitration. then, in the case where twi may be either a master or a slave, the user must manage the pseudo multi-master mode described in the steps below. 1. program twi in slave mode (sadr + msdis + sven) and perform a slave access (if twi is addressed). 2. if the twi has to be set in master mo de, wait until the txcomp flag is at 1. 3. program the master mode (dadr + svdis + msen) an d start the transfer (ex: start + write in thr). 4. as soon as the master mode is enabled, the twi scans th e bus in order to detect if it is busy or free. when the bus is considered free, twi initiates the transfer. 5. as soon as the transfer is initiate d and until a stop condition is sent, the arbitration becomes relevant and the user must monitor the arblst flag. 6. if the arbitration is lost (arblst is set to 1), the user must program the twi in slave mode in case the master that won the arbitration is required to access the twi. 7. if the twi has to be set in slave mode, wait until txcomp flag is at 1 and then program the slave mode. note: if the arbitration is lost and the tw i is addressed, the twi will not acknowledge ev en if it is programmed in slave mode as soon as arblst is set to 1. then the master must repeat sadr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 732 figure 34-22. programmer sends data while the bus is busy figure 34-23. arbitration cases the flowchart shown in figure 34-24 gives an example of read and write operations in multi-master mode. twck twd data sent by a master stop sent by the master start sent by the twi data sent by the twi bus is busy bus is free a transfer is programmed (dadr + w + start + write thr) transfer is initiated twi data transfer transfer is kept bus is considered as free twck bus is busy bus is free a transfer is programmed (dadr + w + start + write thr) transfer is initiated twi data transfer transfer is kept bus is considered as free data from a master data from twi s 0 s0 0 1 1 1 arblst s 0 s 0 0 1 1 1 twd s0 0 1 1 1 1 1 arbitration is lost twi stops sending data p s 0 1 p 0 1 1 1 1 data from the master data from the twi arbitration is lost the master stops sending data transfer is stopped transfer is programmed again (dadr + w + start + write thr) twck twd
733 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 34-24. multi-master flowchart programm the slave mode: sadr + msdis + sven svacc = 1 ? txcomp = 1 ? gacc = 1 ? decoding of the programming sequence prog seq ok ? change sadr svread = 1 ? read status register rxrdy= 1 ? read twi_rhr txrdy= 1 ? eosacc = 1 ? write in twi_thr need to perform a master access ? program the master mode dadr + svdis + msen + clk + r / w read status register arblst = 1 ? mread = 1 ? txrdy= 0 ? write in twi_thr data to send ? rxrdy= 0 ? read twi_rhr data to read? stop transfer read status register txcomp = 0 ? general call treatment yes yes yes yes yes yes yes yes yes yes yes yes yes yes no no no no no no no no no no no no no no no no start
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 734 34.7.5 slave mode 34.7.5.1 definition slave mode is defined as a mode where the device receives the clock and the address from another device called the master. in this mode, the device never initiates and never completes the transmission (start, repeated start and stop conditions are always provided by the master). 34.7.5.2 application block diagram figure 34-25. slave mode typical application block diagram 34.7.5.3 programming slave mode the following fields must be prog rammed before entering slave mode: 1. twi_smr.sadr: the slave device address is used in order to be accessed by master devices in read or write mode. 2. twi_cr.msdis: disables the master mode. 3. twi_cr.sven: enable s the slave mode. as the device receives the clock, va lues written in twi_cwgr are ignored. 34.7.5.4 receiving data after a start or repeated st art condition is detected and if the addr ess sent by the mast er matches with the slave address programmed in the sadr (slave address) field, svacc (slave access) flag is set and svread (slave read) indicates the direction of the transfer. svacc remains high until a stop condition or a repeated start is detected. when such a condition is detected, the eosacc (end of slave access) flag is set. read sequence in the case of a read sequence (svread is high), twi transfers data written in the twi_thr (twi transmit holding register) until a st op condition or a repeated_start + an address different fr om sadr is detected. note that at the end of the read sequence txcomp (transmission complete) fl ag is set and svacc reset. as soon as data is written in the twi_thr, the txrdy (tr ansmit holding register ready) flag is reset, and it is set when the internal shifter is empty and the sent data acknowledged or not. if the data is not acknowledged, the nack flag is set. note that a stop or a repeated start always follows a nack. see figure 34-26 . host with twi interface twd twck lcd controller slave 1 slave 2 slave 3 rr v dd host with twi interface host with twi interface master
735 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 write sequence in the case of a write sequence (svread is low), the rxrdy (receive holding register ready) flag is set as soon as a character has been received in the twi_rhr (twi receive holding register). rxrdy is reset when reading the twi_rhr. twi continues receiving data until a stop condition or a repeate d_start + an address different from sadr is detected. note that at the end of the writ e sequence txcomp flag is set and svacc reset. see figure 34-27 . clock synchronization sequence if twi_rhr is not read in time, the twi performs a clock synchronization. clock synchronization information is give n by the bit sclws (clock wait state). see figure 34-30 . clock stretching sequence if twi_thr is not written in time, the twi performs a clock stretching. clock stretching information is given by the bit sclws (clock wait state). see figure 34-29 . general call in the case where a general call is performe d, the gacc (general call access) flag is set. after gacc is set, the user must interpret the me aning of the general call and decode the new address programming sequence. see figure 34-28 . 34.7.5.5 data transfer read operation the read mode is defined as a data requirement from the master. after a start or a repeated start c ondition is detected, the decoding of the address starts. if the slave address (sadr) is decoded, svacc is set and svread indicates the direction of the transfer. until a stop or repeated start co ndition is detected, twi continues sending data loaded in the twi_thr. if a stop condition or a repeated start + an address diff erent from sadr is de tected, svacc is reset. figure 34-26 describes the write operation.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 736 figure 34-26. read access ordered by a master notes: 1. when svacc is low, the state of svread becomes irrelevant. 2. txrdy is reset when data has been transmitted from twi_thr to the internal shifter and set when this data has been acknowledged or non acknowledged. write operation the write mode is defined as a data transmission from the master. after a start or a repeated start, the decoding of the add ress starts. if the sl ave address is decoded, svacc is set and svread in dicates the direction of the transfer (svread is low in this case). until a stop or repeated start co ndition is detected, twi stores the received data in the twi_rhr. if a stop condition or a repeated start + an address diff erent from sadr is de tected, svacc is reset. figure 34-27 describes the write operation. figure 34-27. write access ordered by a master notes: 1. when svacc is low, the state of svread becomes irrelevant. 2. rxrdy is set when data has been transmitted from the inter nal shifter to the twi_rhr and reset when this data is read. write thr read rhr svread has to be taken into account only while svacc is active twd txrdy nack svacc svread eosvacc sadr s adr r na r a data a a data na s/sr data na p/s/sr sadr matches, twi answers with an ack sadr does not match, twi answers with a nack ack/nack from the master rxrdy read rhr svread has to be taken into account only while svacc is active twd svacc svread eosvacc sadr does not match, twi answers with a nack sadr s adr w na w a data a a data na s/sr data na p/s/sr sadr matches, twi answers with an ack
737 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 general call the general call is performed in order to change the address of the slave. if a general call is detected, gacc is set. after the detection of general call, it is up to the programmer to decode the commands which come afterwards. in case of a write command, the programmer has to decode the programming sequence and program a new sadr if the programming sequence matches. figure 34-28 describes the general call access. figure 34-28. master performs a general call note: this method allows the user to create a personal pr ogramming sequence by choosing the programming bytes and the number of them. the programming sequence has to be provided to the master. 0000000 + w general call p s a general call reset or write dadd a new sadr data1 adata2 a a new sadr programming sequence txd gcacc svacc reset command = 00000110x write command = 00000100x reset after read
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 738 clock synchronization/stretching in both read and write modes, it may occur that tw i_thr/twi_rhr buffer is not filled /emptied before transmission/reception of a new character. in this case, to avoid sending/receiving undesired data, a clock stretching/synchronization mechanism is implemented. clock stretching in read mode the clock is tied low during the acknowledge phase if the internal shifter is empty and if a stop or repeated start condit ion was not detected. it is tied low until the internal sh ifter is loaded. figure 34-29 describes clock stretching in read mode. figure 34-29. clock stretching in read mode notes: 1. txrdy is reset when data has been written in the twi_thr to the internal shifter and set when this data has been acknowledged or non acknowledged. 2. at the end of the read sequence, txcomp is set after a stop or afte r a repeated_start + an address different from sadr. 3. sclws is automatically set when the clock stretching mechanism is started. data1 the clock is stretched after the ack, the state of twd is undefined during clock stretching sclws svacc svread txrdy twck twi_thr txcomp the data is memorized in twi_thr until a new value is written twi_thr is transmitted to the shift register ack or nack from the master data0data0 data2 1 2 1 clock is tied low by the twi as long as thr is empty s sadr s r data0 a a data1 a data2 na s xxxxxxx 2 write thr as soon as a start is detected
739 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 clock synchronization in write mode the clock is tied low outside of the acknowledge phase if the internal shifter and the twi_rhr is full. if a stop or repeated_start condition was not detect ed, it is tied low un til twi_rhr is read. figure 34-30 describes the clock synchronization in write mode. figure 34-30. clock synchronization in write mode notes: 1. at the end of the read sequence, txcomp is set after a stop or after a repeated_start + an address different from sadr. 2. sclws is automatically set when the clock synchronization mechanism is started and automatically reset when the mechanism is finished. rd data0 rd data1 rd data2 svacc svread rxrdy sclws txcomp data1 data2 scl is stretched on the last bit of data1 as soon as a start is detected twck twd twi_rhr clock is tied low by the twi as long as rhr is full data0 is not read in the rhr adr s sadr w a data0 a a data2 data1 s na
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 740 reversal after a repeated start reversal of read to write the master initiates the communication by a read command and finishes it by a write command. figure 34-31 describes the repeated start + reversal from read to write mode. figure 34-31. repeated start + reversal from read to write mode note: 1. txcomp is only set at the end of the transmission because after the repeated start, sadr is detected again. s sadr r a data0 a data1 sadr sr na w a data2 a data3 a p cleared after read data0 data1 data2 data3 svacc svread twd twi_thr twi_rhr eosacc txrdy rxrdy txcomp as soon as a start is detected
741 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 reversal of write to read the master initiates the communication by a wr ite command and finishes it by a read command. figure 34-32 describes the repeated start + reversal from write to read mode. figure 34-32. repeated start + reversal from write to read mode notes: 1. in this case, if twi_thr has not been written at the e nd of the read command, the clock is automatically stretched befo re the ack. 2. txcomp is only set at the end of the transmission because after the repeated start, sadr is detected again. 34.7.5.6 using the peripheral dma controller (pdc) in slave mode the use of the pdc significantly reduces the cpu load. data transmit with the pdc in slave mode the following procedure shows an example of data transmission with pdc. 1. initialize the transmit pdc (m emory pointers, transfer size). 2. start the transfer by setting the pdc txten bit. 3. wait for the pdc endtx flag by using eit her the polling method or the endtx interrupt. 4. disable the pdc by setting the pdc txtdis bit. 5. (optional) wait for the txcomp flag in twi_sr before disabling the peripheral clock if required. data receive with the pdc in slave mode the following procedure shows an example of data transm ission with pdc where the number of characters to be received is known. 1. initialize the receive pdc (mem ory pointers, transfer size). 2. set the pdc rxten bit. 3. wait for the pdc endrx flag by using eith er the polling method or the endrx interrupt. 4. disable the pdc by setting the pdc rxtdis bit. 5. (optional) wait for the txcomp flag in twi_sr before disabling the peripheral clock if required. 34.7.5.7 read write flowcharts the flowchart shown in figure 34-33 gives an example of read and write op erations in slave mode. a polling or interrupt method can be used to check the status bits. t he interrupt method requires that the interrupt enable register (twi_ier) be configured first. s sadr w a data0 a data1 sadr sr a r a data2 a data3 na p cleared after read data0 data2 data3 data1 txcomp txrdy rxrdy as soon as a start is detected read twi_rhr svacc svread twd twi_rhr twi_thr eosacc
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 742 figure 34-33. read write flowchart in slave mode 34.7.6 register write protection to prevent any single software error from corrupting twi behavior, certain re gisters in the address space can be write-protected by settin g the wpen bit in the twi write protection mode register (twi_wpmr). if a write access to a write- protected register is detected, the wpvs flag in the twi write protection status register (twi_wpsr) is set and the wpvsrc field shows t he register in which the write access has been attempted. the wpvs bit is automatically clea red after reading the twi_wpsr. the following registers can be write-protected: ? twi slave mode register ? twi clock waveform generator register set the slave mode: sadr + msdis + sven svacc = 1 ? txcomp = 1 ? gacc = 1 ? decoding of the programming sequence prog seq ok ? change sadr svread = 0 ? read status register rxrdy= 0 ? read twi_rhr txrdy= 1 ? eosacc = 1 ? write in twi_thr end general call treatment no no no no no no no no
743 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.8 two-wire interface (twi2) user interface note: all unlisted offset values are considered as ?reserved?. table 34-7. register mapping offset register name access reset 0x00 control register twi_cr write-only ? 0x04 master mode register twi_mmr read/write 0x00000000 0x08 slave mode register twi_smr read/write 0x00000000 0x0c internal address register twi_iadr read/write 0x00000000 0x10 clock waveform generator register twi_cwgr read/write 0x00000000 0x14?0x1c reserved ? ? ? 0x20 status register twi_sr read-only 0x0000f009 0x24 interrupt enable register twi_ier write-only ? 0x28 interrupt disable re gister twi_idr write-only ? 0x2c interrupt mask register twi_imr read-only 0x00000000 0x30 receive holding register twi_rhr read-only 0x00000000 0x34 transmit holding register twi_thr write-only ? 0x38?0xe0 reserved ? ? ? 0xe4 write protection mode register twi_wpmr read/write 0x00000000 0xe8 write protection status regi ster twi_wpsr read-only 0x00000000 0xec?0xfc reserved ? ? ? 0x100?0x128 reserved for pdc registers ? ? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 744 34.8.1 twi control register name: twi_cr address: 0x40018000 (0), 0x4001c000 (1) access: write-only ? start: send a start condition 0: no effect. 1: a frame beginning with a start bit is transmitted acco rding to the features defined in the mode register. this action is necessary for th e twi to read data from a slave. when configured in master mode with a write operation, a frame is sent as soon as the user writes a char acter in the transmit ho lding register (twi_thr). ? stop: send a stop condition 0: no effect. 1: stop condition is sent just after completing the current byte transmission in master read mode. ? in single data byte master read, the start and stop must both be set. ? in multiple data bytes master read, the stop must be set after the last data received but one. ? in master read mode, if a nack bit is received, the stop is automatically performed. ? in master data write operation, a stop condition is sent when transmission of the current data has ended. ? msen: twi master mode enabled 0: no effect. 1: enables the master mode (msdis must be written to 0). note: switching from slave to master mo de is only permitted when txcomp = 1. ? msdis: twi master mode disabled 0: no effect. 1: the master mode is disabled, all pending data is transmitted. the shifter and holding characters (if it contains data) are transmitted in case of write operation. in read operation, the character being transferred must be completely received before disabling. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 swrst quick svdis sven msdis msen stop start
745 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? sven: twi slave mode enabled 0: no effect. 1: enables the slave mode ( svdis must be written to 0) note: switching from master to slave mo de is only permitted when txcomp = 1. ? svdis: twi slave mode disabled 0: no effect. 1: the slave mode is disabled. the shifter a nd holding characters (if it contains data) are transmitted in case of read oper- ation. in write operation, the character being transferred must be completely received before disabling. ? quick: smbus quick command 0: no effect. 1: if master mode is enabled, a smbus quick command is sent. ? swrst: software reset 0: no effect. 1: equivalent to a system reset.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 746 34.8.2 twi master mode register name: twi_mmr address: 0x40018004 (0), 0x4001c004 (1) access: read/write ? iadrsz: internal device address size ? mread: master read direction 0: master write direction. 1: master read direction. ? dadr: device address the device address is used to access slave devices in read or write mode. these bits are only used in master mode. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ?d a d r 15 14 13 12 11 10 9 8 ???m r e a d?? i a d r s z 76543210 ???????? value name description 0 none no internal device address 1 1_byte one-byte internal device address 2 2_byte two-byte internal device address 3 3_byte three-byte internal device address
747 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.8.3 twi slave mode register name: twi_smr address: 0x40018008 (0), 0x4001c008 (1) access: read/write this register can only be written if the wpen bit is cleared in the twi write protection mode register . ? sadr: slave address the slave device address is used in slave mode in order to be accessed by master devices in read or write mode. sadr must be programmed before enabling the slave mode or af ter a general call. writes at other times have no effect. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? sadr 15 14 13 12 11 10 9 8 ?????? 76543210 ????????
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 748 34.8.4 twi internal address register name: twi_iadr address: 0x4001800c (0), 0x4001c00c (1) access: read/write ? iadr: internal address 0, 1, 2 or 3 bytes depending on iadrsz. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 iadr 15 14 13 12 11 10 9 8 iadr 76543210 iadr
749 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.8.5 twi clock waveform generator register name: twi_cwgr address: 0x40018010 (0), 0x4001c010 (1) access: read/write this register can only be written if the wpen bit is cleared in the twi write protection mode register . twi_cwgr is only used in master mode. ? cldiv: clock low divider the scl low period is defined as follows: t low = ((cldiv 2 ckdiv ) + 4 t peripheral clock ? chdiv: clock high divider the scl high period is defined as follows: t high = ((chdiv 2 ckdiv ) + 4 t peripheral clock ? ckdiv: clock divider the ckdiv is used to increase both scl high and low periods. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????? c k d i v 15 14 13 12 11 10 9 8 chdiv 76543210 cldiv
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 750 34.8.6 twi status register name: twi_sr address: 0x40018020 (0), 0x4001c020 (1) access: read-only ? txcomp: transmission completed (automatically set / reset) txcomp used in master mode : 0: during the length of the current frame. 1: when both holding register and internal shif ter are empty and stop condition has been sent. txcomp behavior in master mode can be seen in figure 34-8 and in figure 34-10 . txcomp used in slave mode : 0: as soon as a start is detected. 1: after a stop or a repeated start + an address different from sadr is detected. txcomp behavior in slave mode can be seen in figure 34-29 , figure 34-30 , figure 34-31 and figure 34-32 . ? rxrdy: receive holding register ready (automatically set / reset) 0: no character has been received si nce the last twi_rhr read operation. 1: a byte has been received in the twi_rhr since the last read. rxrdy behavior in master mode can be seen in figure 34-10 . rxrdy behavior in slave mode can be seen in figure 34-27 , figure 34-30 , figure 34-31 and figure 34-32 . ? txrdy: transmit holding register ready (automatically set / reset) txrdy used in master mode : 0: the transmit holding register has not been transferred into internal shifter. set to 0 when writing into twi_thr. 1: as soon as a data byte is transferred from twi_thr to internal shifter or if a nack error is detected, txrdy is set at the same time as txcomp and nack. txrdy is also set when msen is set (enable twi). txrdy behavior in master mode can be seen in figure 34.7.3.4 . txrdy used in slave mode : 0: as soon as data is written in th e twi_thr, until this data has been transm itted and acknowledged (ack or nack). 1: it indicates that the twi_thr is empty and that data has been transmitted and acknowledged. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txbufe rxbuff endtx endrx eosacc sclws arblst nack 76543210 ?o v r e gacc svacc svread txrdy rxrdy txcomp
751 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 if txrdy is high and if a nack has been detected, the transmissi on will be stopped. thus when trdy = nack = 1, the programmer must not fill tw i_thr to avoid losing it. txrdy behavior in slave mode can be seen in figure 34-26 , figure 34-29 , figure 34-31 and figure 34-32 . ? svread: slave read (automatically set / reset) this bit is only used in slave mode. when svacc is low (no slave access has been detected) svread is irrelevant. 0: indicates that a write acce ss is performed by a master. 1: indicates that a read access is performed by a master. svread behavior can be seen in figure 34-26 , figure 34-27, figure 34-31 and figure 34-32 . ? svacc: slave access (automatically set / reset) this bit is only used in slave mode. 0: twi is not addressed. svacc is automatically cleared after a nack or a stop condition is detected. 1: indicates that the address decodin g sequence has matched (a master has sent sadr). svacc remains high until a nack or a stop condition is detected. svacc behavior can be seen in figure 34-26 , figure 34-27, figure 34-31 and figure 34-32 . ? gacc: general call ac cess (clear on read) this bit is only used in slave mode. 0: no general call has been detected. 1: a general call has been detected. after the detection of general call, if need be, the programmer may acknowledge this access and decode the following bytes and respond according to the value of the bytes. gacc behavior can be seen in figure 34-28 . ? ovre: overrun erro r (clear on read) this bit is only used in master mode. 0: twi_rhr has not been loaded while rxrdy was set 1: twi_rhr has been loaded while rxrdy was set. reset by read in twi_sr when txcomp is set. ? nack: not acknowledg ed (clear on read) nack used in master mode : 0: each data byte has been correctly receiv ed by the far-end side twi slave component. 1: a data byte or an address byte has not been acknowledged by the slave component. set at the same time as txcomp. nack used in slave read mode : 0: each data byte has been correctly received by the master. 1: in read mode, a data byte has not be en acknowledged by the master. when nack is set, the programmer must not fill twi_thr even if txrdy is set, because that means that the master will stop the data transfer or reinitiate it. note that in slave write mode all data are acknowledged by the twi.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 752 ? arblst: arbitration lost (clear on read) this bit is only used in master mode. 0: arbitration won. 1: arbitration lost. another master of t he twi bus has won the multi-master arbitrat ion. txcomp is set at the same time. ? sclws: clock wait state (automatically set / reset) this bit is only used in slave mode. 0: the clock is not stretched. 1: the clock is stretched. twi_thr / twi_rhr buffer is not filled / emptied be fore transmission / reception of a new character. sclws behavior can be seen in figure 34-29 and figure 34-30 . ? eosacc: end of slave access (clear on read) this bit is only used in slave mode. 0: a slave access is being performed. 1: the slave access is finished. end of slave access is automa tically set as soon as svacc is reset. eosacc behavior can be seen in figure 34-31 and figure 34-32 . ? endrx: end of rx buffer 0: the receive counter register has not reached 0 since the last write in twi_rcr or twi_rncr. 1: the receive counter register has reached 0 since the last write in twi_rcr or twi_rncr. ? endtx: end of tx buffer 0: the transmit counter register has not reached 0 since the last write in twi_tcr or twi_tncr. 1: the transmit counter register has reached 0 since the last write in twi_tcr or twi_tncr. ? rxbuff: rx buffer full 0: twi_rcr or twi_rncr have a value other than 0. 1: both twi_rcr and twi_rncr have a value of 0. ? txbufe: tx buffer empty 0: twi_tcr or twi_tncr have a value other than 0. 1: both twi_tcr and twi_tncr have a value of 0.
753 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.8.7 twi interrupt enable register name: twi_ier address: 0x40018024 (0), 0x4001c024 (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? txcomp: transmission completed interrupt enable ? rxrdy: receive holding regi ster ready interrupt enable ? txrdy: transmit holding register ready interrupt enable ? svacc: slave access interrupt enable ? gacc: general call ac cess interrupt enable ? ovre: overrun error interrupt enable ? nack: not acknowledge interrupt enable ? arblst: arbitration lost interrupt enable ? scl_ws: clock wait state interrupt enable ? eosacc: end of slave access interrupt enable ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? rxbuff: receive buffer full interrupt enable ? txbufe: transmit buffer empty interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txbufe rxbuff endtx endrx eosacc scl_ws arblst nack 76543210 ?o v r e gacc svacc ? txrdy rxrdy txcomp
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 754 34.8.8 twi interrupt disable register name: twi_idr address: 0x40018028 (0), 0x4001c028 (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? txcomp: transmission completed interrupt disable ? rxrdy: receive holding regist er ready interrupt disable ? txrdy: transmit holding register ready interrupt disable ? svacc: slave access interrupt disable ? gacc: general call ac cess interrupt disable ? ovre: overrun error interrupt disable ? nack: not acknowledg e interrupt disable ? arblst: arbitration lost interrupt disable ? scl_ws: clock wait state interrupt disable ? eosacc: end of slave access interrupt disable ? endrx: end of receive buffer interrupt disable ? endtx: end of transmit buffer interrupt disable ? rxbuff: receive buffer full interrupt disable ? txbufe: transmit buffer empty interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txbufe rxbuff endtx endrx eosacc scl_ws arblst nack 76543210 ?o v r e gacc svacc ? txrdy rxrdy txcomp
755 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.8.9 twi interrupt mask register name: twi_imr address: 0x4001802c (0), 0x4001c02c (1) access: read-only the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. ? txcomp: transmission completed interrupt mask ? rxrdy: receive holding regi ster ready interrupt mask ? txrdy: transmit holding register ready interrupt mask ? svacc: slave access interrupt mask ? gacc: general call ac cess interrupt mask ? ovre: overrun error interrupt mask ? nack: not acknowle dge interrupt mask ? arblst: arbitration lost interrupt mask ? scl_ws: clock wait state interrupt mask ? eosacc: end of slave access interrupt mask ? endrx: end of receive buffer interrupt mask ? endtx: end of transmit buffer interrupt mask ? rxbuff: receive buffer full interrupt mask ? txbufe: transmit buff er empty interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txbufe rxbuff endtx endrx eosacc scl_ws arblst nack 76543210 ?o v r e gacc svacc ? txrdy rxrdy txcomp
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 756 34.8.10 twi receive holding register name: twi_rhr address: 0x40018030 (0), 0x4001c030 (1) access: read-only ? rxdata: master or slave receive holding data 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 rxdata
757 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.8.11 twi transmit holding register name: twi_thr address: 0x40018034 (0), 0x4001c034 (1) access: write-only ? txdata: master or slave transmit holding data 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 txdata
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 758 34.8.12 twi write protection mode register name: twi_wpmr address: 0x400180e4 (0), 0x4001c0e4 (1) access: read/write ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x545749 (?twi? in ascii). 1: enables the write protecti on if wpkey corres ponds to 0x545749 (?twi? in ascii). see section 34.7.6 ?register write protection? for the list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x545749 passwd writing any other value in this field abort s the write operation of the wpen bit. always reads as 0
759 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 34.8.13 twi write protection status register name: twi_wpsr address: 0x400180e8 (0), 0x4001c0e8 (1) access: read-only ? wpvs: write protection violation status 0: no write protection violation has occu rred since the last re ad of the twi_wpsr. 1: a write protection violation has occu rred since the last read of the twi_w psr. if this violation is an unauthorized attempt to write a protected register, the violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc shows the re gister address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 wpvsrc 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 760 35. universal asynchronous receiver transmitter (uart) 35.1 description the universal asynchronous receiver transmitter featur es a two-pin uart that can be used for communication and trace purposes and offers an ideal medium for in-situ programming solutions. moreover, the association with a peripheral dma controll er (pdc) permits packet handling for these tasks with processor time reduced to a minimum. the optical link transceiver establis hes electrically isolat ed serial communication with hand-held equipment, such as calibrators compliant with ansi-c12.18 or iec62056-21 norms. 35.2 embedded characteristics ? two-pin uart ? independent receiver and transmitter with a common programmable baud rate generator ? even, odd, mark or space parity generation ? parity, framing and overrun error detection ? automatic echo, local loopback and remote loopback channel modes ? digital filter on receive line ? interrupt generation ? support for two pdc channels with connection to receiver and transmitter ? optical link transceiver for communication co mpliant with ansi-c12.18 or iec62056-21 norms 35.3 block diagram figure 35-1. uart functi onal block diagram peripheral dma controller baud rate generator transmit receive interrupt control parallel input/ output utxd urxd uart_irq apb bus clock bridge peripher a l clock pmc uart table 35-1. uart pin description pin name description type urxd uart receive data input utxd uart transmit data output
761 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 35.4 product dependencies 35.4.1 i/o lines the uart pins are multiplexed with pio lines. the user must first configure the corresponding pio controller to enable i/o line operations of the uart. 35.4.2 power management the uart clock can be controlled through the power manage ment controller (pmc). in this case, the user must first configure the pmc to enable the uart clock. usually, the pe ripheral identifier used for this purpose is 1. 35.4.3 interrupt source the uart interrupt line is connected to one of the interrupt sources of the interrupt controller. interrupt handling requires programming of the interrupt controller before configuring the uart. 35.4.4 optical interface the uart optical interface requires configuration of the pmc to generate 4096 khz or 8192 khz on the plla prior to any transfer. 35.5 functional description the uart operates in asynchronous mode only and supports only 8-bit character handling (with parity). it has no clock pin. the uart is made up of a receiver and a transmitter that operate independently, and a common baud rate generator. receiver timeout and transmitter time guard are not implemented. however, all the implemented features are compatible with those of a standard usart. 35.5.1 baud rate generator the baud rate generator provides the bit period clock named baud rate clock to both the receiver and the transmitter. the baud rate clock is the peripheral clock divided by 16 times the clock divisor (cd) value written in the baud rate generator register (uart_brgr). if uart_brgr is se t to 0, the baud rate clock is disabled and the uart remains inactive. the maximum allowable baud rate is peripheral clock divided by 16. the minimum allowable baud rate is peripheral clock divided by (16 x 65536). table 35-2. i/o lines instance signal i/o line peripheral uart0 urxd0 pb4 a uart0 utxd0 pb5 a uart1 urxd1 pc1 a uart1 utxd1 pc0 a baud rate f peripheral clock 16 cd -------------------------------- - =
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 762 figure 35-2. baud rate generator 35.5.2 receiver 35.5.2.1 receiver reset, enable and disable after device reset, the uart receiver is disabled and must be enabled before being used. the receiver can be enabled by writing the control register (uart_cr) with t he bit rxen at 1. at this command, the receiver starts looking for a start bit. the programmer can disable the receiver by writing uart_cr with the bit rxdis at 1. if the receiver is waiting for a start bit, it is immediatel y stopped. however, if the receiver has already detected a start bit and is receiving the data, it waits for the stop bit before actually stopping its operation. the receiver can be put in reset state by writing uart_c r with the bit rstrx at 1. in this case, the receiver immediately stops its current operations and is disabled, whatever its cu rrent state. if rstrx is applied when data is being processed, this data is lost. 35.5.2.2 start detection and data sampling the uart only supports asynchronous operations, and this affects only its receiver. the uart receiver detects the start of a received character by samp ling the urxd signal until it detects a valid start bit. a low level (space) on urxd is interpreted as a valid start bit if it is detected for more than seven cycles of the sampling clock, which is 16 times the baud rate. hence, a space that is longer than 7/16 of the bit perio d is detected as a valid start bit. a space which is 7/16 of a bit period or shorter is ignore d and the receiver continues to wait for a valid start bit. when a valid start bit has been detected, the receiver sample s the urxd at the theoretical midpoint of each bit. it is assumed that each bit lasts 16 cycles of the sampling clock (1-bit period) so the bit sampling point is eight cycles (0.5-bit period) after the start of the bit. the first sampling point is therefore 24 cycl es (1.5-bit periods) after detecting the falling edge of the start bit. each subsequent bit is sampled 16 cycles (1-bit period) after the previous one. figure 35-3. start bit detection peripheral clock 16-bit counter 0 baud rate clock cd cd out divide by 16 0 1 >1 receiver sampling clock d0 d1 d2 d3 d4 d5 d6 d7 p s s d0 d1 d2 d3 d4 d5 d6 d7 p urxd rststa rxrdy ovre stop stop
763 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 35-4. character reception 35.5.2.3 receiver ready when a complete character is received, it is transf erred to the receive holding register (uart_rhr) and the rxrdy status bit in the status r egister (uart_sr) is se t. the bit rxrdy is au tomatically cleared when uart_rhr is read. figure 35-5. receiver ready 35.5.2.4 receiver overrun the ovre status bit in uart_sr is set if uart_rhr has not been read by the software (or the pdc) since the last transfer, the rxrdy bit is still se t and a new character is received. ovre is cleared when the software writes a 1 to the bit rststa (reset status) in uart_cr. figure 35-6. receiver overrun 35.5.2.5 parity error each time a character is received, the receiver calculates the parity of the received data bits, in accordance with the field par in the mode register (uar t_mr). it then compares the result wit h the received parity bit. if different, the parity error bit pare in uart_sr is set at the same time rxrdy is set. the parity bit is cleared when uart_cr is written with the bit rststa (reset status) at 1. if a new character is received before the reset status command is written, the pare bit remains at 1. d0 d1 d2 d3 d4 d5 d6 d7 urxd true start detection sampling parity bit stop bit example: 8-bit, parity enabled 1 stop 1 bit period 0.5 bit period d0 d1 d2 d3 d4 d5 d6 d7 p s s d0 d1 d2 d3 d4 d5 d6 d7 p urxd read uart_rhr rxrdy d0 d1 d2 d3 d4 d5 d6 d7 p s s d0 d1 d2 d3 d4 d5 d6 d7 p urxd rstst a rxrdy ovre stop stop
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 764 figure 35-7. parity error 35.5.2.6 receiver framing error when a start bit is detected, it generat es a character reception when all the data bits have been sampled. the stop bit is also sampled and when it is de tected at 0, the frame (framing error) bit in uart_sr is set at the same time the rxrdy bit is set. the frame bit remains high unt il the control register (uar t_cr) is written with the bit rststa at 1. figure 35-8. receiver framing error 35.5.2.7 receiver digital filter the uart embeds a digital filter on the receive line. it is disabled by default and can be enabled by writing a logical 1 in the filter bit of uart_mr. when enabled, the receive line is sampled using the 16x bit clock and a three-sample filter (majority 2 over 3) determines the value of the line. 35.5.3 transmitter 35.5.3.1 transmitter reset, enable and disable after device reset, the uart trans mitter is disabled and must be enabled before being used. the transmitter is enabled by writing uart_cr with the bit txen at 1. fr om this command, the transmit ter waits for a character to be written in the transmit hold ing register (uart_thr) before actually starting the transmission. the programmer can disable the transmitter by writing uart_cr with the bit tx dis at 1. if the transmitter is not operating, it is immediately stopped. however, if a character is being processed into the internal shift register and/or a character has been written in the uart_thr, the characters are completed before the transmitter is actually stopped. the programmer can also put the transmitter in its rese t state by writing the uart _cr with the bit rsttx at 1. this immediately stops the transmitter, whether or not it is processing characters. 35.5.3.2 transmit format the uart transmitter drives the pin utxd at the baud rate clock speed. the line is driven depending on the format defined in uart_mr and the data stored in the internal shift register. one start bit at level 0, then the 8 data bits, from the lowest to the highest bit, one optional parity bit and one stop bit at 1 are consecutively shifted stop d0 d1 d2 d3 d4 d5 d6 d7 p s urxd rststa rxrdy pare wrong parity bit d0 d1 d2 d3 d4 d5 d6 d7 p s urxd rststa rxrdy frame stop bit detected at 0 stop
765 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 out as shown in the following figure. the field pare in uart_mr defines whether or not a parity bit is shifted out. when a parity bit is enabled, it can be selected between an odd parity, an even parity, or a fixed space or mark bit. figure 35-9. character transmission 35.5.3.3 transmitter control when the transmitter is enabl ed, the bit txrdy (transmitt er ready) is set in uart_s r. the transmission starts when the programmer writes in the uart_thr, and after the written character is transferred from uart_thr to the internal shift register. the txrdy bit remains high until a second character is wr itten in uart_thr. as soon as the first character is completed, t he last character written in uart_thr is transferred into the internal shift register and txrdy rises again, showin g that the holding register is empty. when both the internal shift register and uart_thr are empty, i.e., all the characte rs written in uart_thr have been processed, the txempty bit rises after the last stop bit has been completed. figure 35-10. transmitter control 35.5.4 optical interface to use the optical interface circuitry, the plla clock must be r eady and programmed to generate a frequency within the range of 4096 up to 8192 khz. this range allo ws a modulation by a clock with an adjustable frequency from 30 up to 60 khz. the optical interface is enabled by writing a 1 to the bit opt_en in uart_mr (see ?uart mode register? on page 772 ). when opt_en = 1, the urxd pad is automatically configured in analog mode and the analog comparator is enabled (see figure 35-11 on page 766 ). to match the characteristics of the of f-chip optical receiver circuitry, the voltage reference threshold of the embedded comparator can be adjusted from vddio/10 up to vdd/2 by programming the opt_cmpth field in uart_mr. d0 d1 d2 d3 d4 d5 d6 d7 utxd start bit parity bit stop bit example: parity enabled baud rate clock uart_thr shift register utxd txrdy txempty data 0 data 1 data 0 data 0 data 1 data 1 s s p p write data 0 in uart_thr write data 1 in uart_thr stop stop
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 766 the nrz output of the uart transmitte r sub-module is modulated with the 30 up to 60 khz modulation clock prior to driving the pio controller. a logical 0 on the uart transmitter sub-module output generates the said modulated signal (see figure 35-12 on page 767 ) having a frequency programmable from 30 khz up to 60 khz (38 khz is the default value assuming the plla clock frequency is 8192 khz). a logical 1 on the uart transmitter sub-module output generates a stuck-at 1 output signal (no modulation). the idle polarity of the modulated signal is 1 (opt_mdinv = 0 in uart_mr). the idle polarity of the modulated signal can be inve rted by writing a 1 to the opt_mdinv bit in uart_mr. the duty cycle of the modulated signal can be adjusted fr om 6.25% up to 50% (default value) by steps of 6.25% by programming the opt_duty field in uart_mr. figure 35-11. optical interface block diagram opt_en opt_clkdiv opt_duty opt_mdinv opt_cmpth opt_en baud rate generator transmit receive interrupt control power management controller peripheral clock uart_irq uart pllack 0 pio_irq 1 on optical clock divider optical duty cycle generator /8 1 o p tical modulation parallel input/ output utxd urxd analog comparator 0 vth opt_en opt_rxinv o ptical receive lo g ic
767 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 35-12. optical interface waveforms the default configuration values of the optical link circui tries allow the 38 khz modulation, a 50% duty cycle and an idle polarity allowing a direct drive of an ir led through a resistor (see figure 35-13 on page 768 ). refer to the section ?electrical charac teristics? for drive capability of the buffer associated wit h the utxd output. in case of direct drive of the ir led as shown in figure 35-13 on page 768 , the pio must be programmed in multi- driver mode (open-drain). to do so, the adequate index and values must be programmed into the pio multi-driver enable register (pio_mder) (status reported on the pio multi-driver status register (pio_mdsr)). refer to the section ?parallel in put/output (pio)? section for details. if an off-chip current amp lifier is used to drive the transmitting of the ir led, the pio may be programmed in default drive mode (non open-drain) for the line index dr iving the utxd output, or in open-drain mode depending on the type of external circuitry. uart transmitter ouput utxd (opt_mdinv = 1) utxd (opt_mdinv = 0) t peripheral clock * ( 8 * (opt_clkdiv + 8) ) opt_duty = 0 opt_duty = 3 opt_duty = 7 utxd (opt_en = 0) opt_en = 1 opt_mdinv = 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 768 figure 35-13. optical interface connected to ir components 35.5.5 peripheral dm a controller (pdc) both the receiver and the transmitter of the uart are connected to a pdc. the pdc channels are programmed via registers that are m apped within the uart user interface from the offset 0x100. the status bits are reported in uart_sr and generate an interrupt. the rxrdy bit triggers the pdc channel data transfer of the receiver. this results in a read of the data in uart_rhr. the txrdy bit triggers the pdc channel data transfer of the transmi tter. this results in a write of data in uart_thr. 35.5.6 test modes the uart supports three test modes. these modes of operation are programmed by using the chmode field in uart_mr. the automatic echo mode allows bit-by-bit retransmission. when a bit is received on the urxd line, it is sent to the utxd line. the transmitter operates norm ally, but has no effect on the utxd line. the local loopback mode allows the transmitted characte rs to be received. utxd and urxd pins are not used and the output of the transmitter is in ternally connected to the input of t he receiver. the urxd pin level has no effect and the utxd line is he ld high, as in idle state. the remote loopback mode directly connects the urxd pin to the utxd line. the transmitter and the receiver are disabled and have no effect. this mode allows a bit-by-bit retransmission. uart pio utxd urxd txd rxd resistor pio_mdsr [utxd] ir led vddio vddio phototransisto r 1 1 0 0 0 0
769 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 35-14. test modes receiver transmitter disabled rxd txd receiver transmitter disabled rxd txd v dd disabled receiver transmitter disabled rxd txd disabled automatic echo local loopback remote loopback v dd
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 770 35.6 universal asynchronous receiver tr ansmitter (uart) user interface table 35-3. register mapping offset register name access reset 0x0000 control register uart_cr write-only ? 0x0004 mode register uart_mr read/write 0x0013_0000 0x0008 interrupt enable register uart_ier write-only ? 0x000c interrupt disable register uart_idr write-only ? 0x0010 interrupt mask register uart_imr read-only 0x0 0x0014 status register uart_sr read-only ? 0x0018 receive holding register uart_rhr read-only 0x0 0x001c transmit holding register uart_thr write-only ? 0x0020 baud rate generator register uart_brgr read/write 0x0 0x0024?0x003c reserved ? ? ? 0x0040?0x00e8 reserved ? ? ? 0x00ec?0x00fc reserved ? ? ? 0x0100?0x0128 reserved for pdc registers ? ? ?
771 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 35.6.1 uart control register name: uart_cr address: 0x400e0600 (0), 0x48004000 (1) access: write-only ? rstrx: reset receiver 0: no effect. 1: the receiver logic is reset and disabled. if a ch aracter is being received, the reception is aborted. ? rsttx: reset transmitter 0: no effect. 1: the transmitter logic is reset and disabled. if a char acter is being transmitted, the transmission is aborted. ? rxen: receiver enable 0: no effect. 1: the receiver is enabled if rxdis is 0. ? rxdis: receiver disable 0: no effect. 1: the receiver is disabled. if a character is being processe d and rstrx is not set, the character is completed before the receiver is stopped. ? txen: transmitter enable 0: no effect. 1: the transmitter is enabled if txdis is 0. ? txdis: transmitter disable 0: no effect. 1: the transmitter is disabled. if a character is being pr ocessed and a character has been written in the uart_thr and rsttx is not set, both characters are completed before the transmitter is stopped. ? rststa: reset status 0: no effect. 1: resets the status bits pare, frame and ovre in the uart_sr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????r s t s t a 76543210 txdis txen rxdis rxen rsttx rstrx ? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 772 35.6.2 uart mode register name: uart_mr address: 0x400e0604 (0), 0x48004004 (1) access: read/write ? opt_en: uart optical interface enable ? opt_rxinv: uart receive data inverted ? opt_mdinv: uart modulated data inverted ? filter: receiver digital filter 0 (disabled): uart does not filter the receive line. 1 (enabled): uart filters the receive line using a three-sample filter (16x -bit clock) (2 over 3 majority). ?par: parity type 31 30 29 28 27 26 25 24 ? opt_cmpth ? opt_duty 23 22 21 20 19 18 17 16 ? ? ? opt_clkdiv 15 14 13 12 11 10 9 8 chmode ? ? pa r ? 76543210 ? ? ? filter ? opt_mdinv opt_rxinv opt_en value name description 0 disabled the uart transmitter data is not inverted before modulation. 1 enabled the uart transmitter data is inverted before modulation. value name description 0 disabled the comparator data output is not inverted before entering uart. 1 enabled the comparator data output is inverted before entering uart. value name description 0 disabled the output of the modulator is not inverted. 1 enabled the output of the modulator is inverted. value name description 0 even even parity 1odd odd parity 2space space: parity forced to 0 3mark mark: parity forced to 1 4no no parity
773 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? chmode: channel mode ? opt_clkdiv: optical link clock divider 0 to 31: the optical modu lation clock frequency is defined by pllack / (8 * (opt_clkdiv + 8)). ? opt_duty: optical link modulation clock duty cycle ? opt_cmpth: receive path comparator threshold value name description 0 normal normal mode 1 automatic automatic echo 2 local_loopback local loopback 3 remote_loopback remote loopback value name description 0duty_50 modulation clock duty cycle is 50%. 1 duty_43p75 modulation clock duty cycle is 43.75%. 2 duty_37p5 modulation clock duty cycle is 37.5%. 3 duty_31p25 modulation clock duty cycle is 31.75%. 4duty_25 modulation clock duty cycle is 25%. 5 duty_18p75 modulation clock duty cycle is 18.75%. 6 duty_12p5 modulation clock duty cycle is 12.5%. 7 duty_6p25 modulation clock duty cycle is 6.25%. value name description 0 vddio_div2 comparator threshold is vddio/2 volts. 1 vddio_div2p5 comparator threshold is vddio/2.5 volts. 2 vddio_div3p3 comparator threshold is vddio/3.3 volts. 3 vddio_div5 comparator threshold is vddio/5 volts. 4 vddio_div10 comparator threshold is vddio/10 volts.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 774 35.6.3 uart interrupt enable register name: uart_ier address: 0x400e0608 (0), 0x48004008 (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? rxrdy: enable rxrdy interrupt ? txrdy: enable txrdy interrupt ? endrx: enable end of receive transfer interrupt ? endtx: enable end of transmit interrupt ? ovre: enable overrun error interrupt ? frame: enable framing error interrupt ? pare: enable parity error interrupt ? txempty: enable txempty interrupt ? txbufe: enable buffer empty interrupt ? rxbuff: enable buffer full interrupt 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe ? txempty ? 76543210 pare frame ovre endtx endrx ? txrdy rxrdy
775 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 35.6.4 uart interrupt disable register name: uart_idr address: 0x400e060c (0), 0x4800400c (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? rxrdy: disable rxrdy interrupt ? txrdy: disable txrdy interrupt ? endrx: disable end of receive transfer interrupt ? endtx: disable end of transmit interrupt ? ovre: disable overrun error interrupt ? frame: disable framing error interrupt ? pare: disable pari ty error interrupt ? txempty: disable txempty interrupt ? txbufe: disable buffer empty interrupt ? rxbuff: disable buffer full interrupt 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe ? txempty ? 76543210 pare frame ovre endtx endrx ? txrdy rxrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 776 35.6.5 uart interrupt mask register name: uart_imr address: 0x400e0610 (0), 0x48004010 (1) access: read-only the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. ? rxrdy: mask rxrdy interrupt ? txrdy: disable txrdy interrupt ? endrx: mask end of receive transfer interrupt ? endtx: mask end of transmit interrupt ? ovre: mask overrun error interrupt ? frame: mask framing error interrupt ? pare: mask parity error interrupt ? txempty: mask txempty interrupt ? txbufe: mask txbufe interrupt ? rxbuff: mask rxbuff interrupt 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe ? txempty ? 76543210 pare frame ovre endtx endrx ? txrdy rxrdy
777 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 35.6.6 uart status register name: uart_sr address: 0x400e0614 (0), 0x48004014 (1) access: read-only ? rxrdy: receiver ready 0: no character has been received since the last re ad of the uart_rhr, or the receiver is disabled. 1: at least one complete character has been received, transferred to uart_rhr and not yet read. ? txrdy: transmitter ready 0: a character has been written to uart_thr and not yet transfe rred to the internal shift re gister, or the transmitter is disabled. 1: there is no character written to uart_thr not yet transferred to the internal shift register. ? endrx: end of receiver transfer 0: the end of transfer signal from the receiver pdc channel is inactive. 1: the end of transfer signal from the receiver pdc channel is active. ? endtx: end of transmitter transfer 0: the end of transfer signal from t he transmitter pdc channel is inactive. 1: the end of transfer signal from t he transmitter pdc channel is active. ? ovre: overrun error 0: no overrun error has occurred since the last rststa. 1: at least one overrun error has occurred since the last rststa. ?frame: framing error 0: no framing error has occurred since the last rststa. 1: at least one framing error has occurred since the last rststa. ? pare: parity error 0: no parity error has occurred since the last rststa. 1: at least one parity error has occurred since the last rststa. ? txempty: transmitter empty 0: there are characters in uart_thr, or characters being pr ocessed by the transmitter, or the transmitter is disabled. 1: there are no characters in uart_thr and there ar e no characters being processed by the transmitter. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe ? txempty ? 76543210 pare frame ovre endtx endrx ? txrdy rxrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 778 ? txbufe: transmission buffer empty 0: the buffer empty signal from th e transmitter pdc channel is inactive. 1: the buffer empty signal from the transmitter pdc channel is active. ? rxbuff: receive buffer full 0: the buffer full signal from the receiver pdc channel is inactive. 1: the buffer full signal from the receiver pdc channel is active.
779 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 35.6.7 uart receiver holding register name: uart_rhr address: 0x400e0618 (0), 0x48004018 (1) access: read-only ? rxchr: received character last received character if rxrdy is set. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 rxchr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 780 35.6.8 uart transmit holding register name: uart_thr address: 0x400e061c (0), 0x4800401c (1) access: write-only ? txchr: character to be transmitted next character to be transm itted after the current character if txrdy is not set. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 txchr
781 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 35.6.9 uart baud rate generator register name: uart_brgr address: 0x400e0620 (0), 0x48004020 (1) access: read/write ? cd: clock divisor 0: baud rate clock is disabled 1 to 65,535: f peripheral clock / (cd x 16) 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 cd 76543210 cd
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 782 36. universal synchronous asynchrono us receiver transmitter (usart) 36.1 description the universal synchronous asynchronous receiver transceiver (usart) provides one full duplex universal synchronous asynchronous serial link. data frame format is widely programmable (data length, parity, number of stop bits) to support a maximum of standards. the receiv er implements parity error, framing error and overrun error detection. the receiver time-out enables handling variable-length frames and the transmitter timeguard facilitates communications with slow remote devices. multidrop communications are also supported through address bit handling in reception and transmission. the usart features three test modes: remote loopback, local loopback and automatic echo. the usart supports specific operating modes providin g interfaces on rs485, and spi buses, with iso7816 t = 0 or t = 1 smart card slots and infrared transceivers. the hardware handshaking feature enables an out-of-band flow control by automatic management of the pins rts and cts. the usart supports the connection to the peripheral dma controller, which enables data transfers to the transmitter and from the receiver. the pdc provides chained buffer management without any intervention of the processor. 36.2 embedded characteristics ? programmable baud rate generator ? 5- to 9-bit full-duplex synchronous or asynchronous serial communications ? 1, 1.5 or 2 stop bits in asynchronous mode or 1 or 2 stop bits in synchronous mode ? parity generation and error detection ? framing error detection, overrun error detection ? digital filter on receive line ? msb- or lsb-first ? optional break generation and detection ? by 8 or by 16 over-sampling receiver frequency ? optional hardware handshaking rts-cts ? receiver time-out and transmitter timeguard ? optional multidrop mode with address generation and detection ? rs485 with driver control signal ? iso7816, t = 0 or t = 1 protocols for interfacing with smart cards ? nack handling, error counter with repetition and iteration limit ? irda modulation and demodulation ? communication at up to 115.2 kbps ? spi mode ? master or slave ? serial clock programmable phase and polarity ? spi serial clock (sck) frequency up to f peripheral clock /6 ? test modes ? remote loopback, local loopback, automatic echo ? supports connection of: ? two peripheral dma controller channels (pdc) ? offers buffer transfer without processor intervention
783 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? register write protection 36.3 block diagram figure 36-1. usart block diagram 36.4 i/o lines description (peripheral) dma controller channel channel interrupt controller receiver usart interrupt rxd txd sck usart pio controller cts rts transmitter baud rate generator pmc peripheral clock apb peripheral clock/div bus clock bridge user interface table 36-1. i/o line description name description type active level sck serial clock i/o ? txd transmit serial data or master out slave in (mosi) in spi master mode or master in slave out (miso) in spi slave mode i/o ? rxd receive serial data or master in slave out (miso) in spi master mode or master out slave in (mosi) in spi slave mode input ? cts clear to send or slave select (nss) in spi slave mode input low rts request to send or slave select (nss) in spi master mode output low
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 784 36.5 product dependencies 36.5.1 i/o lines the pins used for interfacing the usart may be multip lexed with the pio lines. the programmer must first program the pio controller to assign the desired usart pins to their peripheral function. if i/o lines of the usart are not used by the application, they can be used for other purposes by the pio controller. to prevent the txd line fr om falling when the usart is disabled, the use of an internal pull up is mandatory. if the hardware handshaking feature is used, the internal pull up on txd must also be enabled. 36.5.2 power management the usart is not continuously clocked. the programm er must first enable the usart clock in the power management controller (pmc) before using the usart. however, if the application does not require usart table 36-2. i/o lines instance signal i/o line peripheral usart0 cts0 pa20 a usart0 rts0 pa19 a usart0 rxd0 pb16 a usart0 sck0 pb18 a usart0 txd0 pb17 a usart1 cts1 pa18 a usart1 rts1 pa17 a usart1 rxd1 pa11 a usart1 sck1 pa16 a usart1 txd1 pa12 a usart2 cts2 pa15 a usart2 rts2 pa14 a usart2 rxd2 pa9 a usart2 sck2 pa13 a usart2 txd2 pa10 a usart3 cts3 pa1 a usart3 rts3 pa0 a usart3 rxd3 pa3 a usart3 sck3 pa2 a usart3 txd3 pa4 a usart4 cts4 pa26 a usart4 rts4 pb22 a usart4 rxd4 pb19 a usart4 sck4 pb21 a usart4 txd4 pb20 a
785 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 operations, the usart clock can be st opped when not needed and be restarted later. in this case, the usart will resume its operations where it left off. 36.5.3 interrupt the usart interrupt line is connected on one of the intern al sources of the interrupt controller. using the usart interrupt requires the interrupt controller to be programmed first. table 36-3. peripheral ids instance id usart0 14 usart1 15 usart2 16 usart3 17 usart4 18
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 786 36.6 functional description 36.6.1 baud rate generator the baud rate generator provides the bit period clock, also named the baud rate clock, to both the receiver and the transmitter. the baud rate generator clock source is selected by configuring the usclks field in the usart mode register (us_mr) to one of the following: ? the peripheral clock ? a division of the peripheral clock, where the divi der is product-dependent, but generally set to 8 ? the external clock, available on the sck pin the baud rate generator is based upon a 16-bit divider, which is programmed with the cd field of the baud rate generator register (us_brgr). if a 0 is written to cd, th e baud rate generator does not generate any clock. if a 1 is written to cd, the divider is bypassed and becomes inactive. if the external sck clock is selected, the duration of the low and high levels of the signal provided on the sck pin must be longer than a peripheral clock period. the frequency of the signal provided on sck must be at least 3 times lower than the frequency provided on the peripher al clock in usart mode (fie ld usart_mode differs from 0xe or 0xf), or 6 times lower in spi mode (field usart_mode equals 0xe or 0xf). figure 36-2. baud rate generator 36.6.1.1 baud rate in asynchronous mode if the usart is programmed to operate in asynchronous mode, the selected clock is fi rst divided by cd, which is field programmed in the us_brgr. the resulting clock is provided to the receiver as a sampling clock and then divided by 16 or 8, depending on how th e over bit in the us_mr is programmed. if over is set, the receiver sampling is eight times high er than the baud rate cloc k. if over is cleared, the sampling is performed at 16 times the baud rate clock. the baud rate is calculated as per the following formula: this gives a maximum baud rate of peripheral clock divided by 8, assuming that the peripheral clock is the highest possible clock and that the over bit is set. baud rate calculation example peripheral clock/div 16-bit counter 0 baud rate clock cd cd sampling divider 0 1 >1 sampling clock reserved peripheral clock usclks over sync sync usclks = 3 1 0 2 3 0 1 0 1 fidi sck (clko = 1) sck (clko = 0) baudrate selectedclock 82 over ? () cd () =
787 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 table 36-4 shows calculations of cd to obtain a baud rate at 38,400 bit/s for different source clock frequencies. this table also shows the actual resulting baud rate and the error. the baud rate is calculated with the following formula: the baud rate error is calculated with the following formula. it is not recommended to work with an error higher than 5%. 36.6.1.2 fractional baud rate in asynchronous mode the baud rate generator is subject to the following limitation: the output frequency changes only by integer multiples of the reference frequency. an approach to this problem is to integrate a fractional n clock generator that has a high resolution. the generator architecture is modified to obtain baud rate changes by a fraction of the reference source clock. this fractional part is programmed with the fp field in the us_b rgr. if fp is not 0, the fractional part is activated. the resolution is one eighth of the clock divider. this feature is only available when using usart normal mode. the fractional baud ra te is calculated using the following formula: table 36-4. baud rate example (over = 0) source clock (mhz) expected baud rate (bit/s) calculation result cd actual baud rate (bit/s) error 3,686,400 38,400 6. 00 6 38,400.00 0.00% 4,915,200 38,400 8. 00 8 38,400.00 0.00% 5,000,000 38,400 8. 14 8 39,062.50 1.70% 7,372,800 38,400 12.00 12 38,400.00 0.00% 8,000,000 38,400 13.02 13 38,461.54 0.16% 12,000,000 38,400 19.53 20 37,500.00 2.40% 12,288,000 38,400 20.00 20 38,400.00 0.00% 14,318,180 38,400 23.30 23 38,908.10 1.31% 14,745,600 38,400 24.00 24 38,400.00 0.00% 18,432,000 38,400 30.00 30 38,400.00 0.00% 24,000,000 38,400 39.06 39 38,461.54 0.16% 24,576,000 38,400 40.00 40 38,400.00 0.00% 25,000,000 38,400 40.69 40 38,109.76 0.76% 32,000,000 38,400 52.08 52 38,461.54 0.16% 32,768,000 38,400 53.33 53 38,641.51 0.63% 33,000,000 38,400 53.71 54 38,194.44 0.54% 40,000,000 38,400 65.10 65 38,461.54 0.16% 50,000,000 38,400 81.38 81 38,580.25 0.47% baudrate f peripheral clock cd 16 ? = error 1 expectedbaudrate actualbaudrate -------------------------------------------------- - ?? ?? ?= baudrate selectedclock 82 over ? () cd fp 8 ------- + ?? ?? ?? ?? ---------------------------------------------------------------- =
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 788 the modified architecture is presented in the following figure 36-3 . figure 36-3. fractional baud rate generator 36.6.1.3 baud rate in synchronous mode or spi mode if the usart is programmed to operate in synchronous mode, the selected clock is simply divided by the field cd in the us_brgr. in synchronous mode, if the external cl ock is selected (usclks = 3), the clock is provided directly by the signal on the usart sck pin. no division is active. the value written in us_brgr has no effect. the external clock frequency must be at least 3 times lower than the system clock. in synchronous mode master (usclks = 0 or 1, clko set to 1), the receive part limits the sck maximum frequency tof peripheral clock /3 in usart mode, or f peripheral clock /6 in spi mode. when either the external clock sck or the internal clock divided (peripheral clock/div) is selected, the value programmed in cd must be even if the user has to ens ure a 50:50 mark/space ratio on the sck pin. when the peripheral clock is selected, the baud rate generator ensu res a 50:50 duty cycle on the sck pin, even if the value programmed in cd is odd. 36.6.1.4 baud rate in iso 7816 mode the iso7816 specification defines the bit rate with the following formula: where: ? b is the bit rate ? di is the bit-rate adjustment factor ? fi is the clock frequency division factor ? f is the iso7816 clock frequency (hz) mck/div 16-bit counter 0 baud rate clock cd cd sampling divider 0 1 >1 sampling clock reserved mck usclks over sync sync usclks = 3 1 0 2 3 0 1 0 1 fidi glitch-free logic modulus control fp fp sck (clko = 1) sck (clko = 0) baudrate selectedclock cd ------------------------------------- - = b di fi ----- - f =
789 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 di is a binary value encoded on a 4-bit field, named di, as represented in table 36-5 . fi is a binary value encoded on a 4-bit field, named fi, as represented in table 36-6 . table 36-7 shows the resulting fi/di ratio, which is the rati o between the iso7816 clock and the baud rate clock. if the usart is configured in iso7816 mode, the clock se lected by the usclks field in us_mr is first divided by the value programmed in the field cd in the us_brgr. the resulting clock can be provided to the sck pin to feed the smart card clock inputs. this means that the clko bit can be set in us_mr. this clock is then divided by the value programmed in the fi_di_ratio field in the fi_di_ratio register (us_fidi). this is performed by the sampling divider, which performs a division by up to 2047 in iso7816 mode. the non-integer values of the fi/di ratio are not support ed and the user must program the fi_di_ratio field to a value as close as possible to the expected value. the fi_di_ratio field resets to the value 0x174 (372 in decimal) and is the most common divider between the iso7816 clock and the bit rate (fi = 372, di = 1). figure 36-4 shows the relation between the elementary time unit, corresponding to a bit time, and the iso 7816 clock. figure 36-4. elementary time unit (etu) table 36-5. binary and decimal values for di di field 0001 0010 0011 0100 0101 0110 1000 1001 di (decimal) 1 2 4 8 16 32 12 20 table 36-6. binary and decimal values for fi fi field 0000 0001 0010 0011 0100 0101 0110 1001 1010 1011 1100 1101 fi (decimal) 372 372 558 744 1116 1488 1860 512 768 1024 1536 2048 table 36-7. possible values for the fi/di ratio fi/di 372 558 744 1116 1488 1806 512 768 1024 1536 2048 1 372 558 744 1116 1488 1860 512 768 1024 1536 2048 2 186 279 372 558 744 930 256 384 512 768 1024 4 93 139.5 186 279 372 465 128 192 256 384 512 8 46.5 69.75 93 139.5 186 232.5 64 96 128 192 256 16 23.25 34.87 46.5 69.75 93 116.2 32 48 64 96 128 32 11.62 17.43 23.25 34.87 46.5 58.13 16 24 32 48 64 12 31 46.5 62 93 124 155 42.66 64 85.33 128 170.6 20 18.6 27.9 37.2 55.8 74.4 9 3 25.6 38.4 51.2 76.8 102.4 1 etu iso7816 clock on sck iso7816 i/o line on txd fi_di_ratio iso7816 clock cycles
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 790 36.6.2 receiver and transmitter control after reset, the receiver is disabled. the user must enabl e the receiver by setting the rxen bit in the control register (us_cr). however, the receiver registers can be programmed before the receiver clock is enabled. after reset, the transmitter is disabled. the user must enable it by setting the txen bit in the us_cr. however, the transmitter registers can be programmed before being enabled. the receiver and the transmitter can be enabled together or independently. at any time, the software can perform a reset on the receiver or the transmitter of the usart by setting the corresponding bit, rstrx and rsttx respectively, in the us _cr. the software resets clear the status flag and reset internal state machines but the user interface configuration registers hold the value configured prior to software reset. regardless of what the receiver or the tr ansmitter is performing, the communication is immediately stopped. the user can also independently disabl e the receiver or the transmitter by setting rxdis and txdis respectively in the us_cr. if the receiver is disabled during a character reception, the usart waits until the end of reception of the current character, then the reception is stopped. if the transmitter is disabled while it is operating, the usart waits the end of transmission of both the current character and character being stored in the transmit holding register (us_thr). if a timeguard is programmed, it is handled normally. 36.6.3 synchronous and asynchronous modes 36.6.3.1 transmitter operations the transmitter performs the same in both synchronou s and asynchronous operating modes (sync = 0 or sync = 1). one start bit, up to 9 data bits, one optional parity bit and up to two stop bits are successively shifted out on the txd pin at each falling edge of the programmed serial clock. the number of data bits is selected by the chrl field and the mode 9 bit in us_mr. nine bits are selected by setting the mode 9 bit regardless of the chrl field. the pa rity bit is set according to the par field in us_mr. the even, odd, space, marked or none parity bit can be configured. the ms bf field in the us_mr configures which data bit is sent first. if written to 1, the most significant bit is sent first. if wr itten to 0, the less significant bit is s ent first. the number of stop bits is selected by the nbstop field in the us_mr. the 1.5 stop bit is supported in asynchronous mode only. figure 36-5. character transmit the characters are sent by writing in the transmit hold ing register (us_thr). the transmitter reports two status bits in the channel status register (us_csr): txrdy (transmitter read y), which indicates that us_thr is empty and txempty, which indicates that a ll the characters written in us_thr have been processed. when the current character processing is completed, the last character writte n in us_thr is transferred into the shift register of the transmitter and us_thr becomes empty, thus txrdy rises. both txrdy and txempty bits are low when the transmi tter is disabled. writing a character in us_thr while txrdy is low has no effect and the written character is lost. d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit example: 8-bit, parity enabled one stop baud rate clock
791 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 36-6. transmitter status 36.6.3.2 manchester encoder when the manchester encoder is in use, characte rs transmitted through the usart are encoded based on biphase manchester ii format. to enable this mode, set the man bit in the us_mr to 1. depending on polarity configuration, a logic level (zero or one), is transmitted as a coded signal one-to-zero or zero-to-one. thus, a transition always occurs at the midpoi nt of each bit time. it consumes more bandwidth than the original nrz signal (2x) but the receiver has more error co ntrol since the expected input must show a change at the center of a bit cell. an example of manchester encoded sequence is: the byte 0xb1 or 10110001 encodes to 10 01 10 10 01 01 01 10, assuming the default polarity of the encoder. figure 36-7 illustrates this coding scheme. figure 36-7. nrz to manchester encoding the manchester encoded character can al so be encapsulated by adding both a configurable preamble and a start frame delimiter pattern. depending on the configuration, the preamble is a training sequence, composed of a predefined pattern with a programmable length from 1 to 15 bit times. if the preamble length is set to 0, the preamble waveform is not generated prior to any character. the preamble pattern is chosen among the following sequences: all_one, all_zero, one_zero or zero_one , writing the field tx_pp in the us_man register, the field tx_pl is used to configure the preamble length. figure 36-8 illustrates and defines the valid patterns. to improve flexibility, the enc oding scheme can be configured using the tx _mpol field in the us_man register. if the tx_mpol field is set to zero (default), a logic zero is encoded with a zero-to-one transition and a logic one is encoded with a one-to-zero transition. if the tx_mpol field is set to 1, a logic one is encoded with a one-to-zero transition and a logic zero is encoded with a zero-to-one transition. d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock start bit write us_thr d0 d1 d2 d3 d4 d5 d6 d7 parity bit stop bit txrdy txempty nrz encoded data manchester encoded data 10110001 txd
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 792 figure 36-8. preamble patterns, default polarity assumed a start frame delimiter is to be configured using the onebi t bit in the us_mr. it consists of a user-defined pattern that indicates the beginning of a valid data. figure 36-9 illustrates these patterns. if the start frame delimiter, also known as the start bit, is one bit, (onebit = 1), a logic zero is manchester encoded and indicates that a new character is being sent seria lly on the line. if the start frame delimiter is a synchronization pattern also referred to as sync (one bit to 0), a sequence of three bit times is sent serially on the line to indicate the start of a new character. the sync waveform is in itse lf an invalid manchester waveform as the transition occurs at the middle of the second bit time. two distinct sync patterns are used: the command sync and the data sync. the command sync has a logic one level for one and a half bit times, then a transition to logic zero for the second one and a half bit times. if the modsync bit in the us_mr is set to 1, the next character is a command. if it is set to 0, the next character is a data. when direct memory access is us ed, the modsync field can be immediately updated with a modified character located in memory. to enable this mo de, var_sync bit in us_mr must be set to 1. in this case, the modsync bit in the us_mr is bypassed and the sync configurati on is held in the txsynh in the us_thr. the usart character format is modified and includes sync information. manchester encoded data txd sfd data 8-bit width "all_one" preamble manchester encoded data txd sfd data 8-bit width "all_zero" preamble manchester encoded data txd sfd data 8-bit width "zero_one" preamble manchester encoded data txd sfd data 8-bit width "one_zero" preamble
793 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 36-9. start frame delimiter drift compensation drift compensation is available only in 16x oversampling mode. an hardware recovery system allows a larger clock drift. to enable the hardware system, the bit in the usart_man register must be set. if the rxd edge is one 16x clock cycle from the expected edge, this is consid ered as normal jitter and no corrective actions is taken. if the rxd event is between 4 and 2 clock cycles before the expected edge, then the cu rrent period is shortened by one clock cycle. if the rxd event is between 2 and 3 clock cycles after the expected edge, then the current period is lengthened by one clock cycle. these intervals are considered to be drift and so corrective actions are automatically taken. figure 36-10. bit resynchronization 36.6.3.3 asynchronous receiver if the usart is programmed in asynchronous operating mode (sync = 0), the receiver oversamples the rxd input line. the oversampling is either 16 or 8 times the ba ud rate clock, depending on the over bit in the us_mr. the receiver samples the rxd line. if the line is sampled dur ing one half of a bit time to 0, a start bit is detected and data, parity and stop bits are succe ssively sampled on the bit rate clock. if the oversampling is 16 (over = 0), a st art is detected at the eighth sample to 0. data bits, parity bit and stop bit are assumed to have a duration corresponding to 16 ov ersampling clock cycles. if the oversampling is 8 (over = 1), a start bit is detected at the fourth sample to 0. data bits, parity bit and stop bit are assumed to have a duration corresponding to 8 oversampling clock cycles. manchester encoded data txd sfd data one bit start frame delimiter preamble length is set to 0 manchester encoded data txd sfd data command sync start frame delimiter manchester encoded data txd sfd data data sync start frame delimiter rxd oversampling 16x clock sampling point expected edge tolerance synchro. jump sync jump synchro. error synchro. error
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 794 the number of data bits, first bit sent and parity mode are selected by the same fields and bits as the transmitter, i.e., respectively chrl, mode9, msbf and par. for the synchronization mechanism only , the number of stop bits has no effect on the receiver as it considers only one stop bit, regardless of the field nbstop, so that resynchronization between the receiver and the transmitter can occur. moreover, as soon as the stop bit is sampled, the receiver starts looking for a new start bit so that resynchronization can also be accomplished when the transmitter is operating with one stop bit. figure 36-11 and figure 36-12 illustrate start detection and charac ter reception when usart operates in asynchronous mode. figure 36-11. asynchronous start detection figure 36-12. asynchronous character reception 36.6.3.4 manchester decoder when the man bit in the us_mr is set to 1, the manc hester decoder is enabled. the decoder performs both preamble and start frame delimiter detection. one input line is dedicated to manchester encoded input data. an optional preamble sequence can be defined, its length is us er-defined and totally independent of the emitter side. use rx_pl in us_man register to configure the length of the preamble sequence. if the length is set to 0, no preamble is detected and the function is disabled. in addition, the polarity of the input stream is programmable with rx_mpol bit in us_man register. depending on the desired application the preamble pattern matching is to be defined via the rx_pp field in us_man. see figure 36-8 for available preamble patterns. unlike preamble, the start frame delimiter is shar ed between manchester encoder and decoder. so, if onebit field is set to 1, only a zero encoded manchester can be detected as a valid start frame delimiter. if onebit is set sampling clock (x16) rxd start detection sampling baud rate clock rxd start rejection sampling 12345678 12345670 1234 12345678 9 10111213141516 d0 sampling d0 d1 d2 d3 d4 d5 d6 d7 rxd parity bit stop bit example: 8-bit, parity enabled baud rate clock start detection 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples
795 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 to 0, only a sync pattern is detected as a valid start frame delimiter. decoder operates by detecting transition on incoming stream. if rxd is sampled during one quarter of a bit time to zero, a start bit is detected. see figure 36- 13 . the sample pulse reje ction mechanism applies. the rxidlev bit in the us_man informs the usart of the re ceiver line idle state value (receiver line inactive). the user must define rxidlev to ensure reliable synchronization. by default, rxidlev is set to 1 (receiver line is at level 1 when there is no activity). figure 36-13. asynchronous start bit detection the receiver is activated and starts preamble and frame delimiter detection, sampling the data at one quarter and then three quarters. if a valid preamble pattern or start frame delimiter is detected, th e receiver continues decoding with the same synchronization. if the stream does not match a valid pattern or a valid start frame delimiter, the receiver resynchronizes on the next valid edge.the minimu m time threshold to estimate the bit value is three quarters of a bit time. if a valid preamble (if used) followed with a valid start fr ame delimiter is detected, the incoming stream is decoded into nrz data and passed to usart for processing. figure 36-14 illustrates manchester pattern mismatch. when incoming data stream is passed to the usart, the receiv er is also able to detect manchester code violation. a code violation is a lack of transition in the middle of a bit cell. in this case, mane flag in the us_csr is raised. it is cleared by writing a 1 to the rststa in the us_cr. see figure 36-15 for an example of manchester error detection during data phase. figure 36-14. preamble pattern mismatch manchester encoded data txd 1234 sampling clock (16 x) start detection manchester encoded data txd sfd data preamble length is set to 8 preamble mismatch invalid pattern preamble mismatch manchester coding error
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 796 figure 36-15. manchester error flag when the start frame delimiter is a sync pattern (onebit field to 0), both command and data delimiter are supported. if a valid sync is detected, the received charac ter is written as rxchr field in the us_rhr and the rxsynh is updated. rxchr is set to 1 when the receiv ed character is a command, and it is set to 0 if the received character is a data. this mechanism alleviates and simplifies the direct memory access as the character contains its own sync field in the same register. as the decoder is setup to be used in unipolar mode, the first bit of the frame has to be a zero-to-one transition. 36.6.3.5 radio interface: manchest er encoded usart application this section describes low data rate rf transmission systems and their integrati on with a manchester encoded usart. these systems are based on transmitter and receiver ics that support ask and fsk modulation schemes. the goal is to perform full duplex radi o transmission of characters using two different frequency carriers. see the configuration in figure 36-16 . figure 36-16. manchester encoded characters rf transmission manchester encoded data txd sfd preamble length is set to 4 elementary character bit time manchester coding error detected sampling points preamble subpacket and start frame delimiter were successfully decoded entering usart character area lna vco rf filter demod control bi-dir line pa rf filter mod vco control manchester decoder manchester encoder usart receiver usart emitter ask/fsk upstream receiver ask/fsk downstream transmitter upstream emitter downstream receiver serial configuration interface fup frequency carrier fdown frequency carrier
797 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the usart peripheral is configured as a manc hester encoder/decoder. looking at the downstream communication channel, manchester encoded characters are se rially sent to the rf emitter. this may also include a user defined preamble and a start frame delimiter. mostly , preamble is used in the rf receiver to distinguish between a valid data from a transmitter and signals due to noise. the manchester stream is then modulated. see figure 36-17 for an example of ask modulation scheme. when a logic one is sent to the ask modulator, the power amplifier, referred to as pa, is enabled and tran smits an rf signal at downstream frequency. when a logic zero is transmitted, the rf signal is turned off. if the fsk modulator is activated, two different frequencies are used to transmit data. when a logic 1 is sent, the modulator out puts an rf signal at frequency f0 and switches to f1 if the data sent is a 0. see figure 36-18 . from the receiver side, another carrier frequency is us ed. the rf receiver performs a bit check operation examining demodulated data stream. if a valid pattern is detected, the receiver switches to receiving mode. the demodulated stream is sent to the manchester decoder. be cause of bit checking inside rf ic, the data transferred to the microcontroller is reduced by a user-defined num ber of bits. the manchester preamble length is to be defined in accordance with the rf ic configuration. figure 36-17. ask modulator output figure 36-18. fsk modulator output 36.6.3.6 synchronous receiver in synchronous mode (sync = 1), the receiver samples the rxd signal on each rising edge of the baud rate clock. if a low level is detected, it is consider ed as a start. all data bits, the parity bit and the stop bits are sampled and the receiver waits for the next start bit. synchronous mode operations prov ide a high-speed transfer capability. configuration fields and bits are the same as in asynchronous mode. figure 36-19 illustrates a character rece ption in synchronous mode. manchester encoded data default polarity unipolar output txd ask modulator output uptstream frequency f0 nrz stream 10 0 1 manchester encoded data default polarity unipolar output txd fsk modulator output uptstream frequencies [f0, f0+offset] nrz stream 10 0 1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 798 figure 36-19. synchronous mode character reception 36.6.3.7 receiver operations when a character reception is completed, it is transf erred to the receiv e holding register (us_rhr) and the rxrdy bit in us_csr rises. if a charac ter is completed while the rxrdy is se t, the ovre (overrun error) bit is set. the last character is transferred into us_rhr and ov erwrites the previous one. the ovre bit is cleared by writing a 1 to the rststa (reset status) bit in the us_cr. figure 36-20. receiver status 36.6.3.8 parity the usart supports five parity modes that are selected by writing to the par field in the us_mr. the par field also enables the multidrop mode, see ?multidrop mode? on page 799 . even and odd parity bit generation and error detection are supported. if even parity is selected, the parity generator of the transmitter drives the parity bit to 0 if a number of 1s in the character data bit is even, and to 1 if the number of 1s is odd. accordingly, the receiver parity checker counts the number of received 1s and reports a parity error if the sampled parity bit does not correspond. if odd parity is selected, the parity generator of the transmitter drives the parity bit to 1 if a number of 1s in the character data bit is even, and to 0 if the number of 1s is odd. accordingl y, the receiver parity checker counts the number of received 1s and reports a parity error if the sampled parity bit does not correspond. if the mark parity is used, the parity generator of the transmitter drives the parity bit to 1 for all characters. the receiver parity checker reports an error if the parity bit is sampled to 0. if the space parity is used , the parity generator of the transmitter drives the parity bit to 0 for all characters. the receiver parity checker report s an error if the parity bit is sampled to 1. if parity is disabled, the transmitter does not gen erate any parity bit and the receiver does not report any parity error. d0 d1 d2 d3 d4 d5 d6 d7 rxd start sampling parity bit stop bit example: 8-bit, parity enabled 1 stop baud rate clock d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit parity bit stop bit baud rate clock write us_cr rxrdy ovre d0 d1 d2 d3 d4 d5 d6 d7 start bit parity bit stop bit rststa = 1 read us_rhr
799 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 table 36-8 shows an example of the parity bit for the character 0x41 (character ascii ?a?) depending on the configuration of the usart. because there are two bits set to 1 in the character value, the parity bit is set to 1 when the parity is odd, or configur ed to 0 when the parity is even. when the receiver detects a parity error, it sets the pare (parity error) bit in the us_csr. the pare bit can be cleared by writing a 1 to the rststa bit the us_cr. figure 36-21 illustrates the parity bit status setting and clearing. figure 36-21. parity error 36.6.3.9 multidrop mode if the value 0x6 or 0x07 is written to the par field in the us_mr, the usar t runs in multidrop mode. this mode differentiates the data characters and the address char acters. data is transmitted with the parity bit at 0 and addresses are transmitted with the parity bit at 1. if the usart is configured in multidrop mode, the receiver sets the pare parity error bit when the parity bit is high and the transmitter is able to send a character with the parity bit high when a 1 is written to the senta bit in the us_cr. to handle parity error, the pare bit is cleared when a 1 is written to the rststa bit in the us_cr. the transmitter sends an address byte (parity bit set) wh en senda is written to in th e us_cr. in this case, the next byte written to the us_thr is transmitted as an address. any character written in the us_thr without having written the command senda is transmit ted normally with the parity at 0. 36.6.3.10transmitter timeguard the timeguard feature enables the usart interface with slow remote devices. the timeguard function enables the transmitter to insert an idle state on the txd line between two characters. this idle state actually acts as a long stop bit. table 36-8. parity bit examples character hexadecimal binary parity bit parity mode a 0x41 0100 0001 1 odd a 0x41 0100 0001 0 even a 0x41 0100 0001 1 mark a 0x41 0100 0001 0 space a 0x41 0100 0001 none none d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit bad parity bit stop bit baud rate clock write us_cr pare rxrdy rststa = 1 parity error detect time flags report time
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 800 the duration of the idle state is programmed in the tg field of the transmitter timeguard register (us_ttgr). when this field is written to zero no timeguard is gener ated. otherwise, the transmitter holds a high level on txd after each transmitted byte during the number of bit peri ods programmed in tg in addition to the number of stop bits. as illustrated in figure 36-22 , the behavior of txrdy and txempty status bits is modified by the programming of a timeguard. txrdy rises only when the start bit of the ne xt character is sent, and thus remains to 0 during the timeguard transmission if a character has been written in us_thr. txempty remains low until the timeguard transmission is completed as the timeguard is part of the current character being transmitted. figure 36-22. timeguard operations table 36-9 indicates the maximum length of a timeguard period that the transmitter can ha ndle in relation to the function of the baud rate. 36.6.3.11receiver time-out the receiver time-out provides support in handling variable-length frames. this feature detects an idle condition on the rxd line. when a time-out is detected, the bit timeout in the us_csr rises and can generate an interrupt, thus indicating to the driver an end of frame. the time-out delay period (during which the receiver wait s for a new character) is programmed in the to field of the receiver time-out register (us_rtor). if the to field is wri tten to 0, the receiver ti me-out is disabled and no time-out is detected. the timeout bit in the us_csr remains at 0. otherwise, the receiver loads a 16-bit counter d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock start bit tg = 4 write us_thr d0 d1 d2 d3 d4 d5 d6 d7 parity bit stop bit txrdy txempty tg = 4 table 36-9. maximum timeguard length depending on baud rate baud rate (bit/s) bit time (s) timeguard (ms) 1,200 833 212.50 9,600 104 26.56 14,400 69.4 17.71 19,200 52.1 13.28 28,800 34.7 8.85 38,400 26 6.63 56,000 17.9 4.55 57,600 17.4 4.43 115,200 8.7 2.21
801 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 with the value programmed in to. this counter is dec remented at each bit period and reloaded each time a new character is received. if the counter reaches 0, the time out bit in us_csr rises. then, the user can either: ? stop the counter clock until a new character is received. this is performed by writing a 1 to the sttto (start time-out) bit in the us_cr. in this case, the idle state on rxd before a new character is received will not provide a time-out. this prevents having to handle an interrupt before a character is received and allows waiting for the next idle state on rxd after a frame is received. ? obtain an interrupt while no character is received. this is performed by writing a 1 to the retto (reload and start time-out) bit in the us_cr. if retto is perf ormed, the counter starts counting down immediately from the value to. this enables generation of a periodic interrupt so that a user time-out can be handled, for example when no key is pressed on a keyboard. if sttto is performed, the counter cloc k is stopped until a first character is received. the idle state on rxd before the start of the frame does not provide a time-out. this prevents having to obtain a periodic interrupt and enables a wait of the end of frame when the idle state on rxd is detected. if retto is performed, the counter starts counting down immediately from the value to. this enables generation of a periodic interrupt so that a user time-out can be handled, for example when no key is pressed on a keyboard. figure 36-23 shows the block diagram of th e receiver time-out feature. figure 36-23. receiver time-out block diagram table 36-10 gives the maximum time-out period for some standard baud rates. table 36-10. maximu m time-out period baud rate (bit/s) bit time (s) time-out (ms) 600 1,667 109,225 1,200 833 54,613 2,400 417 27,306 4,800 208 13,653 9,600 104 6,827 14,400 69 4,551 19,200 52 3,413 28,800 35 2,276 38,400 26 1,704 56,000 18 1,170 57,600 17 1,138 200,000 5 328 16-bit time-out counter 0 to timeout baud rate clock = character received retto load clock 16-bit value sttto dq 1 clear
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 802 36.6.3.12framing error the receiver is capable of detecting framing errors. a framing error happens when the stop bit of a received character is detected at level 0. this can occur if t he receiver and the transmitter are fully desynchronized. a framing error is reported on the frame bit of us_csr. the frame bit is asserted in the middle of the stop bit as soon as the framing error is detected. it is clea red by writing a 1 to the rststa bit in the us_cr. figure 36-24. framing error status 36.6.3.13transmit break the user can request the transmitter to generate a break condition on the txd line. a break condition drives the txd line low during at least one complete character. it appears the same as a 0x00 character sent with the parity and the stop bits at 0. however, t he transmitter holds the txd line at least during one character until the user requests the break condition to be removed. a break is transmitted by writing a 1 to the sttbrk bit in the us_cr. this can be performed at any time, either while the transmitter is empty (no character in either the shift register or in us_thr) or when a character is being transmitted. if a break is requested while a character is be ing shifted out, the character is first completed before the txd line is held low. once sttbrk command is requested further sttbrk commands are ignored until the end of the break is completed. the break condition is removed by writing a 1 to the st pbrk bit in the us_cr. if the stpbrk is requested before the end of the minimum break duration (one character, including start, data, parity and stop bits), the transmitter ensures that the break condition completes. the transmitter considers the break as though it is a character, i.e., the sttbrk and stpbrk commands are taken into account only if the txrdy bit in us_csr is to 1 and the start of the br eak condition clears the txrdy and txempty bits as if a character is processed. writing us_cr with both sttbrk and stpbrk bits to 1 can lead to an unpredictable result. all stpbrk commands requested without a previous sttbrk command ar e ignored. a byte written into the transmit holding register while a break is pending, but not started, is ignored. after the break condition, the transmitter returns the txd line to 1 for a minimum of 12 bit times. thus, the transmitter ensures that the remote receiver detects correc tly the end of break and the start of the next character. if the timeguard is programmed with a value higher than 12, the txd line is held high for the timeguard period. after holding the txd line for this period, the transmitter resumes normal operations. figure 36-25 illustrates the effect of both the start break (sttbrk) and st op break (stpbrk) commands on the txd line. d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit parity bit stop bit baud rate clock write us_cr frame rxrdy rststa = 1
803 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 36-25. break transmission 36.6.3.14receive break the receiver detects a break condition when all data, parity and stop bits are low. this corresponds to detecting a framing error with data to 0x00, but frame remains low. when the low stop bit is detected, the receiver assert s the rxbrk bit in us_csr. this bit may be cleared by writing a 1 to the rststa bit in the us_cr. an end of receive break is detected by a high level for at least 2/16 of a bit period in asynchronous operating mode or one sample at high level in synchronous operating mo de. the end of break detection also asserts the rxbrk bit. 36.6.3.15hardware handshaking the usart features a hardware handshaking out-of-band flow control. the rts and cts pins are used to connect with the remote device, as shown in figure 36-26 . figure 36-26. connection with a remote device for hardware handshaking setting the usart to operate with hardware handshakin g is performed by writing the usart_mode field in us_mr to the value 0x2. the usart behavior when hardware handshaking is enabl ed is the same as the behavior in standard synchronous or asynchronous mode, except that the receiver drives the rts pin as described below and the level on the cts pin modifies the behavior of the transmitter as described bel ow. using this mode requires using the pdcchannel for reception. the transmitter can handle hardware handshaking in any case. figure 36-27 shows how the receiver operates if hardware hand shaking is enabled. the rts pin is driven high if the receiver is disabled and if the status rxbuff (receive buffer full ) coming from the pdc channel is high. normally, the remote device does not start transmitting while its cts pin (d riven by rts) is high. as soon as the receiver is enabled, the rts falls, indi cating to the remote device that it can start transmitting. defining a new buffer to the pdc clears the status bit rxbuff and, as a result, asserts the pin rts low. d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock write us_cr txrdy txempty stpbrk = 1 sttbrk = 1 break transmission end of break usart txd cts remote device rxd txd rxd rts rts cts
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 804 figure 36-27. receiver behavior when operating with hardware handshaking figure 36-28 shows how the transmitter operates if hardwar e handshaking is enabled. the cts pin disables the transmitter. if a character is being processing, the transmitter is disabled only after the completion of the current character and transmission of the next charac ter happens as soon as the pin cts falls. figure 36-28. transmitter behavior when operating with hardware handshaking 36.6.4 iso7816 mode the usart features an iso7816-compat ible operating mode. this mode permits interfacing with smart cards and security access modules (sam) communi cating through an iso7816 link. both t = 0 and t = 1 protocols defined by the iso7816 specif ication are supported. setting the usart in iso7816 mode is performed by writ ing the usart_mode field in us_mr to the value 0x4 for protocol t = 0 and to the value 0x5 for protocol t = 1. 36.6.4.1 iso7816 mode overview the iso7816 is a half duplex communication on only one bidirectional line. the baud rate is determined by a division of the clock provided to the remote device (see ?baud rate generator? on page 786 ). the usart connects to a smart card as shown in figure 36-29 . the txd line becomes bidirectional and the baud rate generator feeds the iso7816 clock on the sck pin. as the txd pin becomes bidirectional, its output remains driven by the output of the transmitter but only when the tran smitter is active while its in put is directed to the input of the receiver. the usart is considered as the master of the communication as it generates the clock. figure 36-29. connection of a smart card to the usart when operating in iso7816, either in t = 0 or t = 1 modes, the character format is fixed. the configuration is 8 data bits, even parity and 1 or 2 stop bits, regardless of the values programmed in the chrl, mode9, par and chmode fields. msbf can be used to transmit lsb or m sb first. parity bit (par) can be used to transmit in normal or inverse mode. refer to ?usart mode register? on page 822 and ?par: parity type? on page 823 . rts rxbuff write us_cr rxen = 1 rxd rxdis = 1 cts txd smart card sck clk txd i/o usart
805 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 the usart cannot operate concurrently in both rece iver and transmitter modes as the communication is unidirectional at a time. it has to be configured accordin g to the required mode by enabling or disabling either the receiver or the transmitter as desired. enabling both the re ceiver and the transmitter at the same time in iso7816 mode may lead to unpredictable results. the iso7816 specification defines an inverse transmission format. data bits of the character must be transmitted on the i/o line at their negative value. 36.6.4.2 protocol t = 0 in t = 0 protocol, a character is made up of one start bit, eight data bits, one parity bit and one guard time, which lasts two bit times. the transmitter sh ifts out the bits and does not driv e the i/o line during the guard time. if no parity error is detected, the i/o line remains at 1 during the guard time and the transmi tter can continue with the transmission of the next character, as shown in figure 36-30 . if a parity error is detected by the receiver, it drives the i/o line to 0 during the guard time, as shown in figure 36- 31 . this error bit is also named nack, for non acknowledge. in this case, the character lasts 1 bit time more, as the guard time length is the same and is added to the error bit time which lasts 1 bit time. when the usart is the receiver and it detects an error, it does not load the erroneous character in the receive holding register (us_rhr). it ap propriately sets the pare bit in the status register (us_sr) so that the software can handle the error. figure 36-30. t = 0 protocol without parity error figure 36-31. t = 0 protocol with parity error receive error counter the usart receiver also records the total number of er rors. this can be read in the number of error (us_ner) register. the nb_errors field can record up to 255 errors. reading us_ner automatically clears the nb_errors field. receive nack inhibit the usart can also be configured to inhibit an error. th is can be achieved by setting the inack bit in us_mr. if inack is to 1, no error signal is driven on the i/o line even if a parity bit is detected. moreover, if inack is set, the erroneous received character is stored in the receive holding register, as if no error occurred and the rxrdy bit does rise. d0 d1 d2 d3 d4 d5 d6 d7 rxd parity bit baud rate clock start bit guard time 1 next start bit guard time 2 d0 d1 d2 d3 d4 d5 d6 d7 i/o parity bit baud rate clock start bit guard time 1 start bit guard time 2 d0 d1 error repetition
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 806 transmit character repetition when the usart is trans mitting a character and gets a nack, it c an automatically repeat the character before moving on to the next one. repetition is enabled by writing the max_iteration fiel d in the us_mr at a value higher than 0. each character can be transmitted up to ei ght times; the first transmi ssion plus seven repetitions. if max_iteration does not equal zero, the usart repeat s the character as many times as the value loaded in max_iteration. when the usart repetition number reaches max_it eration and the last repeated character is not acknowledged, the iter bit is set in us_csr. if the repe tition of the character is acknowledged by the receiver, the repetitions are stopped and t he iteration counter is cleared. the iter bit in us_csr can be cleared by writing a 1 to the rstit bit in the us_cr. disable successive receive nack the receiver can limit the number of successive nacks sent back to the remote transm itter. this is programmed by setting the bit dsnack in the us_mr. the maximu m number of nacks transmitted is programmed in the max_iteration field. as soon as max_ iteration is reached, no error signal is driven on the i/o line and the iter bit in the us_csr is set. 36.6.4.3 protocol t = 1 when operating in iso7816 protocol t = 1, the transmission is similar to an asynchronous format with only one stop bit. the parity is generated when transmitting and checked when receiving. parity error detection sets the pare bit in the us_csr. 36.6.5 irda mode the usart features an irda mode supplying half-duplex point-to-point wireless communication. it embeds the modulator and demodulator which al lows a glueless connection to the in frared transceivers, as shown in figure 36-32 . the modulator and demodulator are compliant with the irda specification version 1.1 and support data transfer speeds ranging from 2.4 kb/s to 115.2 kb/s. the irda mode is enabled by setting the usart_mode fiel d in us_mr to the value 0x8. the irda filter register (us_if) is used to configure the demodulator filter. the usart transmitter and receiver operate in a normal asynchronous mode and all parameters are accessible. note that the modulator and the demodulator are activated. figure 36-32. connection to irda transceivers the receiver and the transmitter must be enabled or disa bled depending on the direction of the transmission to be managed. to receive irda signals, the following needs to be done: ? disable tx and enable rx ? configure the txd pin as pio and set it as an output to 0 (to avoid led emission). disable the internal pull- up (better for power consumption). irda transceivers rxd rx txd tx usart demodulator modulator receiver transmitter
807 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? receive data 36.6.5.1 irda modulation for baud rates up to and including 115.2 kb/s, the rzi mo dulation scheme is used. ?0? is represented by a light pulse of 3/16th of a bit time. some exampl es of signal pulse duration are shown in table 36-11 . figure 36-33 shows an example of character transmission. figure 36-33. irda modulation 36.6.5.2 irda baud rate table 36-12 gives some examples of cd values, baud rate erro r and pulse duration. note that the requirement on the maximum acceptable error of 1.87% must be met. table 36-11. irda pulse duration baud rate pulse duration (3/16) 2.4 kb/s 78.13 s 9.6 kb/s 19.53 s 19.2 kb/s 9.77 s 38.4 kb/s 4.88 s 57.6 kb/s 3.26 s 115.2 kb/s 1.63 s bit period 3/16 bit period start bit data bits stop bit 0 0 0 0 0 1 11 1 1 transmitter output txd table 36-12. irda baud rate error peripheral clock baud rate (bit/s) cd baud rate error pulse time (s) 3,686,400 115,200 2 0.00% 1.63 20,000,000 115,200 11 1.38% 1.63 32,768,000 115,200 18 1.25% 1.63 40,000,000 115,200 22 1.38% 1.63 3,686,400 57,600 4 0.00% 3.26 20,000,000 57,600 22 1.38% 3.26 32,768,000 57,600 36 1.25% 3.26 40,000,000 57,600 43 0.93% 3.26 3,686,400 38,400 6 0.00% 4.88 20,000,000 38,400 33 1.38% 4.88 32,768,000 38,400 53 0.63% 4.88 40,000,000 38,400 65 0.16% 4.88
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 808 36.6.5.3 irda demodulator the demodulator is based on the irda receive filter compri sed of an 8-bit down counter which is loaded with the value programmed in us_if. when a falling edge is detected on the rxd pin, the filter counter starts counting down at the peripheral clock speed. if a rising edge is dete cted on the rxd pin, the co unter stops and is reloaded with us_if. if no rising edge is detected when the counter reaches 0, the input of the receiver is driven low during one bit time. figure 36-34 illustrates the operations of the irda demodulator. figure 36-34. irda demodulator operations the programmed value in the us_if register must always meet the following criteria: t peripheral clock (irda_filter + 3) < 1.41 s as the irda mode uses the same logic as the iso7816, no te that the fi_di_ratio fiel d in us_fidi must be set to a value higher than 0 in order to assure irda communications operate correctly. 36.6.6 rs485 mode the usart features the rs485 mode to enable line driv er control. while operatin g in rs485 mode, the usart behaves as though in asynchronous or synchronous mode and configuration of all the parameters is possible. the difference is that the rts pin is driven high when the transmitter is operating. the behavior of the rts pin is controlled by the txempty bit. a typical connecti on of the usart to an rs485 bus is shown in figure 36-35 . 3,686,400 19,200 12 0.00% 9.77 20,000,000 19,200 65 0.16% 9.77 32,768,000 19,200 107 0.31% 9.77 40,000,000 19,200 130 0.16% 9.77 3,686,400 9,600 24 0.00% 19.53 20,000,000 9,600 130 0.16% 19.53 32,768,000 9,600 213 0.16% 19.53 40,000,000 9,600 260 0.16% 19.53 3,686,400 2,400 96 0.00% 78.13 20,000,000 2,400 521 0.03% 78.13 32,768,000 2,400 853 0.04% 78.13 table 36-12. irda baud rate error (continued) peripheral clock baud rate (bit/s) cd baud rate error pulse time (s) mck rxd receiver input pulse rejected 65432 6 1 65432 0 pulse accepted counter value
809 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 36-35. typical connection to a rs485 bus the usart is set in rs485 mode by writing the value 0x1 to the usart_mode field in us_mr. the rts pin is at a level inverse to the txempty bit. significantly, the rts pin remains high when a timeguard is programmed so that the line can remain driven after the last character completion. figure 36-36 gives an example of the rts waveform during a character tr ansmission when the timeguard is enabled. figure 36-36. example of rts drive with timeguard usart rts txd rxd differential bus d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock tg = 4 write us_thr txrdy txempty rts 1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 810 36.6.7 spi mode the serial peripheral interface (spi ) mode is a synchronous serial data li nk that provides communication with external devices in master or slave mode. it also enables communication between processors if an external processor is connected to the system. the serial peripheral interface is essentially a shift register that serially transmits data bits to other spis. during a data transfer, one spi system acts as the ?master? which controls the data flow, while the other devices act as ?slaves'' which have da ta shifted into and out by th e master. different cpus can take turns being masters and one master may simultaneously shift data into multiple slaves. (multiple master protocol is the opposite of single master protocol, where one cpu is always the master whil e all of the others are always slaves.) however, only one slave may drive its output to write dat a back to the master at any given time. a slave device is selected when its nss signal is asse rted by the master. the usart in spi master mode can address only one spi slave because it can generate only one nss signal. the spi system consists of two data lines and two control lines: ? master out slave in (mosi): this data line supplies the ou tput data from the master shifted into the input of the slave. ? master in slave out (miso): this data line supplies the output data from a slave to the input of the master. ? serial clock (sck): this control line is driven by th e master and regulates the flow of the data bits. the master may transmit data at a variety of baud rate s. the sck line cycles once for each bit that is transmitted. ? slave select (nss): this contro l line allows the master to select or deselect the slave. 36.6.7.1 modes of operation the usart can operate in spi master mode or in spi slave mode. operation in spi master mode is programmed by writing 0xe to the usart_mode field in us_mr. in this case the spi lines must be connected as described below: ? the mosi line is driven by the output pin txd ? the miso line drives the input pin rxd ? the sck line is driven by the output pin sck ? the nss line is driven by the output pin rts operation in spi slave mode is programmed by writing to 0xf the usart_mode field in us_mr. in this case the spi lines must be connected as described below: ? the mosi line drives the input pin rxd ? the miso line is driven by the output pin txd ? the sck line drives the input pin sck ? the nss line drives the input pin cts in order to avoid unpredictable behavior, any change of the spi mode must be followed by a software reset of the transmitter and of the receiver (except the initial configuration after a hardware reset). (see section 36.6.7.4 ). 36.6.7.2 baud rate in spi mode, the baud rate generator operates in the same way as in usart synchronous mode. see ?baud rate in synchronous mode or spi mode? on page 788. however, there are some restrictions: in spi master mode: ? the external clock sck must not be selected (usclks 0x3), and the bit clko must be set to 1 in the us_mr, in order to generate correctly the serial clock on the sck pin. ? to obtain correct behavior of the receiver and the transmitter, the value programmed in cd must be superior or equal to 6.
811 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? if the divided peripheral clock is selected, the value programmed in cd must be even to ensure a 50:50 mark/space ratio on the sck pin, this value ca n be odd if the peripheral clock is selected. in spi slave mode: ? the external clock (sck) selection is forced regardless of the value of the usclks field in the us_mr. likewise, the value written in us_brg r has no effect, because the clock is provided directly by the signal on the usart sck pin. ? to obtain correct behavior of the receiver and the trans mitter, the external clock (sck) frequency must be at least 6 times lower than the system clock. 36.6.7.3 data transfer up to nine data bits are successively shifted out on the txd pin at each ri sing or falling edge (depending of cpol and cpha) of the programmed serial clock. there is no start bit, no parity bit and no stop bit. the number of data bits is selected by the chrl field and the mode 9 bi t in the us_mr. the nine bits are selected by setting the mode 9 bit regardless of the chrl field. the msb data bit is always sent first in spi mode (master or slave). four combinations of polarity and phas e are available for data transfers. the clock polarity is programmed with the cpol bit in the us_mr. the clock phase is programmed with the cpha bit. these two parameters determine the edges of the clock signal upon which data is driven and sampled. each of the two parameters has two possible states, resulting in four possible combinations that are incompatible with one another. thus, a master/slave pair must use the same parameter pair values to communicate . if multiple slaves are used and fixed in different configurations, the master must reco nfigure itself each time it needs to communicate with a different slave. table 36-13. spi bus protocol mode spi bus protocol mode cpol cpha 001 100 211 310
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 812 figure 36-37. spi transfer format (cpha = 1, 8 bits per transfer) figure 36-38. spi transfer format (cpha = 0, 8 bits per transfer) 36.6.7.4 receiver and transmitter control see ?receiver and transmitter control? on page 790. 36.6.7.5 character transmission the characters are sent by writing in the transmit holding register (us_thr). an additional condition for transmitting a character can be added when the usart is configured in spi master mode. in the ?usart mode register (spi_mode)? (usart_mr), the value configured on the bit wrdbt can prevent any character 6 sck (cpol = 0) sck (cpol = 1) mosi spi master ->txd spi slave -> rxd nss spi master -> rts spi slave -> cts sck cycle (for reference) msb msb lsb lsb 6 6 5 5 4 4 3 3 2 2 1 1 1 2345 78 6 miso spi master -> rxd spi slave -> txd sck (cpol = 0) sck (cpol = 1) 1 2345 7 mosi spi master -> txd spi slave -> rxd miso spi master -> rxd spi slave -> txd nss spi master -> rts spi slave -> cts sck cycle (for reference) 8 msb msb lsb lsb 6 6 5 5 4 4 3 3 1 1 2 2 6
813 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 transmission (even if us_thr has been written) while the receiver side is not ready (character not read). when wrdbt equals 0, the character is transmi tted whatever the receiver status. if wrdbt is set to 1, the transmitter waits for the receive holding register (us_rhr) to be read before transmitting the character (rxrdy flag cleared), thus preventing any overflow (character loss) on the receiver side. the transmitter reports two status bits in us_csr: tx rdy (transmitter ready), which indicates that us_thr is empty and txempty, which indicates that all the characters written in us_thr have been processed. when the current character processing is completed, the last c haracter written in us_thr is transferred into the shift register of the transmitter and us_t hr becomes empty, thus txrdy rises. both txrdy and txempty bits are low when the transmi tter is disabled. writing a character in us_thr while txrdy is low has no effect and the written character is lost. if the usart is in spi slave mode and if a character must be sent while the us_thr is empty, the unre (underrun error) bit is set. the txd transmission line stays at high level during all this time. the unre bit is cleared by writing a 1 to the rststa (reset status) bit in us_cr. in spi master mode, the slave select line (nss) is asserted at low level one t bit (t bit being the nominal time required to transmit a bit) before the transmission of the msb bit and released at high level one t bit after the transmission of the lsb bit. so, the slave select line (nss) is al ways released between each character transmission and a minimum delay of three t bit always inserted. however, in order to address slave devices supporting the csaat mode (chip select active afte r transfer), the slave select line (nss) can be forced at low level by writing a 1 to the rtsen bit in the us_cr. the slave sele ct line (nss) can be released at high level only by writing a 1 to the rtsdis bit in the us_cr (for example, when all data have been transferred to the slave device). in spi slave mode, the transmitter does not require a falling edge of the slave select line (nss) to initiate a character transmission but only a low le vel. however, this low le vel must be present on the slave select line (nss) at least one t bit before the first serial clock cycl e corresponding to the msb bit. 36.6.7.6 character reception when a character reception is completed, it is transf erred to the receiv e holding register (us_rhr) and the rxrdy bit in the status register (us_csr) rises. if a character is completed while rxrdy is set, the ovre (overrun error) bit is set. the last character is transf erred into us_rhr and overwr ites the previous one. the ovre bit is cleared by writing a 1 to the rststa (reset status) bit in the us_cr. to ensure correct behavior of the rece iver in spi slave mode, the master de vice sending the frame must ensure a minimum delay of one t bit between each character transmission. the receiver does not requir e a falling edge of the slave select line (nss) to initiate a character recepti on but only a low level. however, this low level must be present on the slave select line (nss) at least one t bit before the first serial clock cycle corresponding to the msb bit. 36.6.7.7 receiver timeout because the receiver baud rate clock is active only during data transfers in spi mode, a receiver timeout is impossible in this mode, wh atever the time-out value is (field to) in the us_rtor. 36.6.8 test modes the usart can be programmed to operate in three differ ent test modes. the internal loopback capability allows on-board diagnostics. in loopback mode, the usart inte rface pins are disconnected or not and reconfigured for loopback internally or externally. 36.6.8.1 normal mode normal mode connects the rxd pin on the receiver input and the tr ansmitter output on the txd pin.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 814 figure 36-39. normal mode configuration 36.6.8.2 automatic echo mode automatic echo mode allows bit-by-bit retransmission. when a bit is received on the rxd pin, it is sent to the txd pin, as shown in figure 36-40 . programming the transmitter has no effect on the txd pin. the rxd pin is still connected to the receiver input, th us the receiver remains active. figure 36-40. automatic echo mode configuration 36.6.8.3 local loopback mode local loopback mode connects the output of the transmitte r directly to the input of the receiver, as shown in figure 36-41 . the txd and rxd pins are not used. the rxd pin has no effect on the receiver and the txd pin is continuously driven high, as in idle state. figure 36-41. local loopback mode configuration 36.6.8.4 remote loopback mode remote loopback mode directly connects t he rxd pin to the txd pin, as shown in figure 36-42 . the transmitter and the receiver are disabled and have no effect. this mode allows bit-by-bit retransmission. figure 36-42. remote loopback mode configuration receiver transmitter rxd txd receiver transmitter rxd txd receiver transmitter rxd txd 1 receiver transmitter rxd txd 1
815 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.6.9 register write protection to prevent any single software error from corrupting usar t behavior, certain registers in the address space can be write-protected by setting the wpen bit in the ?usart write protection mode register? (us_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the ?usart write protection status register? (us_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cl eared after read ing the us_wpsr. the following registers can be write-protected: ? ?usart mode register? ? ?usart baud rate generator register? ? ?usart receiver time-out register? ? ?usart transmitter timeguard register? ? ?usart fi di ratio register? ? ?usart irda filter register? ? ?usart manchester configuration register?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 816 36.7 universal synchronous asynchronous recei ver transmitter (usa rt) user interface table 36-14. register mapping offset register name access reset 0x0000 control register us_cr write-only ? 0x0004 mode register us_mr read/write ? 0x0008 interrupt enable register us_ier write-only ? 0x000c interrupt disable register us_idr write-only ? 0x0010 interrupt mask register us_imr read-only 0x0 0x0014 channel status register us_csr read-only ? 0x0018 receive holding register us_rhr read-only 0x0 0x001c transmit holding register us_thr write-only ? 0x0020 baud rate generator re gister us_brgr read/write 0x0 0x0024 receiver time-out register us_rtor read/write 0x0 0x0028 transmitter timeguard register us_ttgr read/write 0x0 0x2c?0x3c reserved ? ? ? 0x0040 fi di ratio register us_fidi read/write 0x174 0x0044 number of errors register us_ner read-only ? 0x0048 reserved ? ? ? 0x004c irda filter register us_if read/write 0x0 0x0050 manchester configuration register us_man read/write 0x30011004 0x0054?0x005c reserved ? ? ? 0x0060?0x00e0 reserved ? ? ? 0x00e4 write protection mode register us_wpmr read/write 0x0 0x00e8 write protection status register us_wpsr read-only 0x0 0x00ec?0x00fc reserved ? ? ? 0x100?0x128 reserved for pdc registers ? ? ?
817 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.1 usart control register name: us_cr address: 0x40024000 (0), 0x40028000 (1), 0x4002c 000 (2), 0x40030000 (3), 0x40034000 (4) access: write-only for spi control, see ?usart control register (spi_mode)? on page 820 . ? rstrx: reset receiver 0: no effect. 1: resets the receiver. ? rsttx: reset transmitter 0: no effect. 1: resets the transmitter. ? rxen: receiver enable 0: no effect. 1: enables the receiver, if rxdis is 0. ? rxdis: receiver disable 0: no effect. 1: disables the receiver. ? txen: transmitter enable 0: no effect. 1: enables the transmitter if txdis is 0. ? txdis: transmitter disable 0: no effect. 1: disables the transmitter. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????r t s d i sr t s e n?? 15 14 13 12 11 10 9 8 retto rstnack rstit senda sttto stpbrk sttbrk rststa 76543210 txdis txen rxdis rxen rsttx rstrx ? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 818 ? rststa: reset status bits 0: no effect. 1: resets the status bits pare, frame, ovre, manerr and rxbrk in us_csr. ? sttbrk: start break 0: no effect. 1: starts transmission of a break after the characters present in us_thr and the transmit shift register have been trans- mitted. no effect if a break is already being transmitted. ? stpbrk: stop break 0: no effect. 1: stops transmission of the break after a minimum of one character length and transmits a high level during 12-bit periods. no effect if no break is being transmitted. ? sttto: start time-out 0: no effect. 1: starts waiting for a charac ter before clocking the time-out counter. resets the status bit timeout in us_csr. ? senda: send address 0: no effect. 1: in multidrop mode only, the next character writte n to the us_thr is sent with the address bit set. ? rstit: reset iterations 0: no effect. 1: resets iteration in us_csr. no effect if the iso7816 is not enabled. ? rstnack: reset non acknowledge 0: no effect 1: resets nack in us_csr. ? retto: rearm time-out 0: no effect 1: restart time-out
819 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? rtsen: request to send enable 0: no effect. 1: drives the pin rts to 0. ? rtsdis: request to send disable 0: no effect. 1: drives the pin rts to 1.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 820 36.7.2 usart control register (spi_mode) name: us_cr (spi_mode) address: 0x40024000 (0), 0x40028000 (1), 0x4002c 000 (2), 0x40030000 (3), 0x40034000 (4) access: write-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 822 . ? rstrx: reset receiver 0: no effect. 1: resets the receiver. ? rsttx: reset transmitter 0: no effect. 1: resets the transmitter. ? rxen: receiver enable 0: no effect. 1: enables the receiver, if rxdis is 0. ? rxdis: receiver disable 0: no effect. 1: disables the receiver. ? txen: transmitter enable 0: no effect. 1: enables the transmitter if txdis is 0. ? txdis: transmitter disable 0: no effect. 1: disables the transmitter. ? rststa: reset status bits 0: no effect. 1: resets the status bits ovre, unre in us_csr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????r c sf c s?? 15 14 13 12 11 10 9 8 ???????r s t s t a 76543210 txdis txen rxdis rxen rsttx rstrx ? ?
821 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? fcs: force spi chip select applicable if usart ope rates in spi master mo de (usart_mode = 0xe): 0: no effect. 1: forces the slave select line nss (rts pin) to 0, even if usart is not transmitting, in order to address spi slave devices supporting the csaat mode (chip select active after transfer). ? rcs: release spi chip select applicable if usart ope rates in spi master mo de (usart_mode = 0xe): 0: no effect. 1: releases the slave select line nss (rts pin).
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 822 36.7.3 usart mode register name: us_mr address: 0x40024004 (0), 0x40028004 (1), 0x4002c 004 (2), 0x40030004 (3), 0x40034004 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? . for spi configuration, see ?usart mode register (spi_mode)? on page 826 . ? usart_mode: usart mode of operation the pdc transfers are supported in all usart modes of operation. ? usclks: clock selection 31 30 29 28 27 26 25 24 onebit modsync man filter ? max_iteration 23 22 21 20 19 18 17 16 invdata var_sync dsnack inack over clko mode9 msbf 15 14 13 12 11 10 9 8 chmode nbstop par sync 76543210 chrl usclks usart_mode value name description 0x0 normal normal mode 0x1 rs485 rs485 0x2 hw_handshaking hardware handshaking 0x3 ? reserved 0x4 is07816_t_0 is07816 protocol: t = 0 0x6 is07816_t_1 is07816 protocol: t = 1 0x8 irda irda 0xe spi_master spi master 0xf spi_slave spi slave value name description 0 mck peripheral cl ock is selected 1 div peripheral clock divi ded (div=8) is selected 2?r e s e r v e d 3 sck serial clock (sck) is selected
823 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? chrl: character length ? sync: synchronous mode select 0: usart operates in asynchronous mode. 1: usart operates in synchronous mode. ?par: parity type ? nbstop: number of stop bits ? chmode: channel mode ?msbf: bit order 0: least significant bit is sent/received first. 1: most significant bit is sent/received first. ? mode9: 9-bit character length 0: chrl defines character length 1: 9-bit character length value name description 0 5_bit character length is 5 bits 1 6_bit character length is 6 bits 2 7_bit character length is 7 bits 3 8_bit character length is 8 bits value name description 0 even even parity 1 odd odd parity 2 space parity forced to 0 (space) 3 mark parity forced to 1 (mark) 4n on o p a r i t y 6 multidrop multidrop mode value name description 0 1_bit 1 stop bit 1 1_5_bit 1.5 stop bit (sync = 0) or reserved (sync = 1) 2 2_bit 2 stop bits value name description 0 normal normal mode 1 automatic automatic echo. receiver input is connected to the txd pin. 2 local_loopback local loopback. transmitter output is connected to th e receiver input. 3 remote_loopback remote loopback. rxd pin is internally connected to the txd pin.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 824 ? clko: clock output select 0: the usart does not drive the sck pin. 1: the usart drives the sck pin if usclks does not select the external clock sck. ? over: oversampling mode 0: 16 oversampling 1: 8 oversampling ? inack: inhibit non acknowledge 0: the nack is generated. 1: the nack is not generated. ? dsnack: disable successive nack 0: nack is sent on the iso line as soon as a parity erro r occurs in the received char acter (unless inack is set). 1: successive parity errors are counted up to the value specified in the max_iteration field. these parity errors gener- ate a nack on the iso line. as soon as this value is reache d, no additional nack is sent on the iso line. the flag iteration is asserted. note: max_iteration field must be set to 0 if dsnack is cleared. ? invdata: inverted data 0: the data field transmitted on txd line is the same as the one written in us_thr or the co ntent read in us_rhr is the same as rxd line. normal mode of operation. 1: the data field transmitted on txd line is inverted (voltage polarity only) compared to the value written on us_thr or the content read in us_rhr is inverted compared to what is received on rxd line (or iso7816 io line). inverted mode of operation, useful for contactless card application. to be used with configuration bit msbf. ? var_sync: variable synchronization of command/data sync start frame delimiter 0: user defined configuration of command or data sync field depending on modsync value. 1: the sync field is updated when a character is written into us_thr. ? max_iteration: maximum numb er of automatic iteration 0?7: defines the maximum number of iterations in mode iso7816, protocol t = 0. ? filter: receive line filter 0: the usart does not filter the receive line. 1: the usart filters the receive line using a three-sa mple filter (1/16-bit clock) (2 over 3 majority). ? man: manchester encoder/decoder enable 0: manchester encoder/decoder are disabled. 1: manchester encoder/decoder are enabled. ? modsync: manchester synchronization mode 0:the manchester start bit is a 0 to 1 transition 1: the manchester start bi t is a 1 to 0 transition.
825 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? onebit: start frame delimiter selector 0: start frame delimiter is command or data sync. 1: start frame delimiter is one bit.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 826 36.7.4 usart mode register (spi_mode) name: us_mr (spi_mode) address: 0x40024004 (0), 0x40028004 (1), 0x4002c 004 (2), 0x40030004 (3), 0x40034004 (4) access: read/write this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 822 . ? usart_mode: usart mode of operation ? usclks: clock selection ? chrl: character length ? cpha: spi clock phase ? applicable if usart operates in spi mode (usart_mode = 0xe or 0xf): 0: data is changed on the leading edge of sp ck and captured on the following edge of spck. 1: data is captured on the leading edge of spck and changed on the following edge of spck. cpha determines which edge of spck causes data to change and which edge causes data to be captured. cpha is used with cpol to produce the required clock/data relationship between master and slave devices. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? wrdbt ? clko ? cpol 15 14 13 12 11 10 9 8 ???????c p h a 76543210 chrl usclks usart_mode this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? . value name description 0xe spi_master spi master 0xf spi_slave spi slave value name description 0 mck peripheral clock is selected 1 div peripheral clock divi ded (div=8) is selected 3 sck serial clock slk is selected value name description 3 8_bit character length is 8 bits
827 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? cpol: spi clock polarity applicable if usart operates in spi mode (slave or master, usart_mode = 0xe or 0xf): 0: the inactive state value of spck is logic level zero. 1: the inactive state value of spck is logic level one. cpol is used to determine the inactive state value of the serial clock (spck). it is used with cpha to produce the required clock/data relationship between master and slave devices. ? clko: clock output select 0: the usart does not drive the sck pin. 1: the usart drives the sck pin if usclks does not select the external clock sck. ? wrdbt: wait read data before transfer 0: the character transmission starts as soon as a char acter is written into us_t hr (assuming txrdy was set). 1: the character transmission starts when a character is written and only if rxrdy flag is cleared (receive holding regis- ter has been read).
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 828 36.7.5 usart interrupt enable register name: us_ier address: 0x40024008 (0), 0x40028008 (1), 0x4002c 008 (2), 0x40030008 (3), 0x40034008 (4) access: write-only for spi specific configuration, see ?usart interrupt enable register (spi_mode)? on page 829 . the following configuration values are valid for all listed bit names of this register: 0: no effect 1: enables the corresponding interrupt. ? rxrdy: rxrdy interrupt enable ? txrdy: txrdy interrupt enable ? rxbrk: receiver br eak interrupt enable ? endrx: end of receive buffer interrupt enable (available in all usart modes of operation) ? endtx: end of transmit buffer interrupt enable (available in all usart modes of operation) ? ovre: overrun error interrupt enable ? frame: framing error interrupt enable ? pare: parity erro r interrupt enable ? timeout: time-out interrupt enable ? txempty: txempty interrupt enable ? iter: max number of repetitions reached interrupt enable ? txbufe: transmit buffer empty interrupt enab le (available in all usart modes of operation) ? rxbuff: receive buffer full interrupt enable (available in all usart modes of operation) ? nack: non acknowledge interrupt enable ? ctsic: clear to send input change interrupt enable 31 30 29 28 27 26 25 24 ???????m a n e 23 22 21 20 19 18 17 16 ? ? ? - ctsic ? ? ? 15 14 13 12 11 10 9 8 ? ? nack rxbuff txbufe iter txempty timeout 76543210 pare frame ovre endtx endrx rxbrk txrdy rxrdy
829 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? mane: manchester er ror interrupt enable 36.7.6 usart interrupt enable register (spi_mode) name: us_ier (spi_mode)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 830 address: 0x40024008 (0), 0x40028008 (1), 0x4002c 008 (2), 0x40030008 (3), 0x40034008 (4) access: write-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 822 . the following configuration values are valid for all listed bit names of this register: 0: no effect 1: enables the corresponding interrupt. ? rxrdy: rxrdy interrupt enable ? txrdy: txrdy interrupt enable ? ovre: overrun error interrupt enable ? txempty: txempty interrupt enable ? unre: spi underrun error interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe unre txempty ? 76543210 ? ? ovre endtx endrx ? txrdy rxrdy
831 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.7 usart interrupt disable register name: us_idr address: 0x4002400c (0), 0x4002800c (1 ), 0x4002c00c (2), 0x4003000c (3), 0x4003400c (4) access: write-only for spi specific configuration, see ?usart interrupt disable register (spi_mode)? on page 832 . the following configuration values are valid for all listed bit names of this register: 0: no effect 1: disables the corresponding interrupt. ? rxrdy: rxrdy interrupt disable ? txrdy: txrdy interrupt disable ? rxbrk: receiver break interrupt disable ? endrx: end of receive buffer transfer interrupt disable (available in all usart modes of operation) ? endtx: end of transmit buffer interrupt disa ble (available in all usart modes of operation) ? ovre: overrun error interrupt enable ? frame: framing error interrupt disable ? pare: parity erro r interrupt disable ? timeout: time-out interrupt disable ? txempty: txempty interrupt disable ? iter: max number of repetitions reached interrupt disable ? txbufe: transmit buffer empty interrupt disable (available in all usart modes of operation) ? rxbuff: receive buffer full interrupt disable (available in all usart modes of operation) ? nack: non acknowledge interrupt disable ? ctsic: clear to send input change interrupt disable 31 30 29 28 27 26 25 24 ???????m a n e 23 22 21 20 19 18 17 16 ? ? ? - ctsic ? ? ? 15 14 13 12 11 10 9 8 ? ? nack rxbuff txbufe iter txempty timeout 76543210 pare frame ovre endtx endrx rxbrk txrdy rxrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 832 ? mane: manchester er ror interrupt disable 36.7.8 usart interrupt disable register (spi_mode) name: us_idr (spi_mode)
833 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 address: 0x4002400c (0), 0x4002800c (1 ), 0x4002c00c (2), 0x4003000c (3), 0x4003400c (4) access: write-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 822 . the following configuration values are valid for all listed bit names of this register: 0: no effect 1: disables the corresponding interrupt. ? rxrdy: rxrdy interrupt disable ? txrdy: txrdy interrupt disable ? ovre: overrun error interrupt disable ? txempty: txempty interrupt disable ? unre: spi underrun error interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe unre txempty ? 76543210 ? ? ovre endtx endrx ? txrdy rxrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 834 36.7.9 usart interrupt mask register name: us_imr address: 0x40024010 (0), 0x40028010 (1), 0x4002c 010 (2), 0x40030010 (3), 0x40034010 (4) access: read-only for spi specific configuration, see ?usart interrupt mask regist er (spi_mode)? on page 835 . the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. ? rxrdy: rxrdy interrupt mask ? txrdy: txrdy interrupt mask ? rxbrk: receiver br eak interrupt mask ? endrx: end of receive buffer interrupt mask (available in all usart modes of operation) ? endtx: end of transmit buffer interrupt mask (available in all usart modes of operation) ? ovre: overrun error interrupt mask ? frame: framing error interrupt mask ? pare: parity error interrupt mask ? timeout: time-out interrupt mask ? txempty: txempty interrupt mask ? iter: max number of repetitions reached interrupt mask ? txbufe: transmit buffer empt y interrupt mask (available in all usart modes of operation) ? rxbuff: receive buffer full interrupt mask (available in all us art modes of operation) ? nack: non acknowledge interrupt mask ? ctsic: clear to send input change interrupt mask 31 30 29 28 27 26 25 24 ???????m a n e 23 22 21 20 19 18 17 16 ? ? ? - ctsic ? ? ? 15 14 13 12 11 10 9 8 ? ? nack rxbuff txbufe iter txempty timeout 76543210 pare frame ovre endtx endrx rxbrk txrdy rxrdy
835 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? mane: manchester error interrupt mask 36.7.10 usart interrupt mask register (spi_mode) name: us_imr (spi_mode)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 836 address: 0x40024010 (0), 0x40028010 (1), 0x4002c 010 (2), 0x40030010 (3), 0x40034010 (4) access: read-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 822 . the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. ? rxrdy: rxrdy interrupt mask ? txrdy: txrdy interrupt mask ? ovre: overrun error interrupt mask ? txempty: txempty interrupt mask ? unre: spi underrun error interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe unre txempty ? 76543210 ? ? ovre endtx endrx ? txrdy rxrdy
837 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.11 usart channe l status register name: us_csr address: 0x40024014 (0), 0x40028014 (1), 0x4002c 014 (2), 0x40030014 (3), 0x40034014 (4) access: read-only for spi specific configuration, see ?usart channel status register (spi_mode)? on page 839 . ? rxrdy: receiver ready (a utomatically set / reset) 0: no complete character has been received since the last read of us_rhr or the receiver is disabled. if characters were being received when the receiver was disabled, rx rdy changes to 1 when the receiver is enabled. 1: at least one complete character has been received and us_rhr has not yet been read. ? txrdy: transmitter ready (automatically set / reset) 0: a character is in the us_thr waiting to be transferred to the transmit shi ft register, or an sttbrk command has been requested, or the transmitter is disabled. as soon as the transmitter is enabled, txrdy becomes 1. 1: there is no character in the us_thr. ? rxbrk: break received/end of break 0: no break received or end of break detected since the last rststa. 1: break received or end of brea k detected since the last rststa. ? endrx: end of rx buffer 0: the receive counter register has not reach ed 0 since the last write in us_rcr or us_rncr (1) . 1: the receive counter register has not reach ed 0 since the last write in us_rcr or us_rncr (1) . ? endtx: end of tx buffer 0: the transmit counter register has not reache d 0 since the last write in us_tcr or us_tncr (1) . 1: the transmit counter register has reached 0 since the last write in us_tcr or us_tncr (1) . ? ovre: overrun error 0: no overrun error has occurred since the last rststa. 1: at least one overrun error has occurred since the last rststa. 31 30 29 28 27 26 25 24 ???????m a n e r r 23 22 21 20 19 18 17 16 cts ? ? ? ctsic ? ? ? 15 14 13 12 11 10 9 8 ? ? nack rxbuff txbufe iter txempty timeout 76543210 pare frame ovre endtx endrx rxbrk txrdy rxrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 838 ?frame: framing error 0: no stop bit has been dete cted low since the last rststa. 1: at least one stop bit has been detected low since the last rststa. ? pare: parity error 0: no parity error has been de tected since the last rststa. 1: at least one parity error has be en detected since the last rststa. ? timeout: receiver time-out 0: there has not been a time-out since the last start time-out command (sttto in us_cr) or the time-out register is 0. 1: there has been a time-out since the last start time-out command (sttto in us_cr). ? txempty: transmitter empty (automatically set / reset) 0: there are characters in either us_thr or the tran smit shift register, or the transmitter is disabled. 1: there are no characters in us_thr , nor in the transmit shift register. ? iter: max number of repetitions reached 0: maximum number of repetitions has not been reached since the last rstit. 1: maximum number of repetitions ha s been reached since the last rstit. ? txbufe: tx buffer empty 0: us_tcr or us_tncr have a value other than 0 (1) . 1: both us_tcr and us_tncr have a value of 0 (1) . ? rxbuff: rx buffer full 0: us_rcr or us_rncr have a value other than 0 (1) . 1: both us_rcr and us_rncr have a value of 0 (1) . note: 1. us_rcr, us_rncr, us_tcr and us_tncr are pdc registers. ? nack: non acknowledge interrupt 0: non acknowledge has not been detected since the last rstnack. 1: at least one non acknowledge has be en detected since the last rstnack. ? ctsic: clear to send input change flag (clear on read) 0: no input change has been detected on th e cts pin since the last read of us_csr. 1: at least one input change has been detected on the cts pin since the last read of us_csr. ? cts: image of cts input 0: cts is set to 0. 1: cts is set to 1. ? manerr: manchester error 0: no manchester error has been detected since the last rststa. 1: at least one manchester error has been detected since the last rststa.
839 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.12 usart channel status register (spi_mode) name: us_csr (spi_mode) address: 0x40024014 (0), 0x40028014 (1), 0x4002c 014 (2), 0x40030014 (3), 0x40034014 (4) access: read-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 822 . ? rxrdy: receiver ready (a utomatically set / reset) 0: no complete character has been received since the last read of us_rhr or the receiver is disabled. if characters were being received when the receiver was disabled, rx rdy changes to 1 when the receiver is enabled. 1: at least one complete character has been received and us_rhr has not yet been read. ? txrdy: transmitter ready (automatically set / reset) 0: a character is in the us_thr waiting to be transferred to the transmit shift register or the transmitter is disabled. as soon as the transmitter is enabled, txrdy becomes 1. 1: there is no character in the us_thr. ? ovre: overrun error 0: no overrun error has occurred since the last rststa. 1: at least one overrun error has occurred since the last rststa. ? txempty: transmitter empty (automatically set / reset) 0: there are characters in either us_thr or the tran smit shift register, or the transmitter is disabled. 1: there are no characters in us_thr , nor in the transmit shift register. ? unre: underrun error 0: no spi underrun error has occurred since the last rststa. 1: at least one spi underrun error has occurred since the last rststa. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe unre txempty ? 76543210 ? ? ovre endtx endrx ? txrdy rxrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 840 36.7.13 usart receive holding register name: us_rhr address: 0x40024018 (0), 0x40028018 (1), 0x4002c 018 (2), 0x40030018 (3), 0x40034018 (4) access: read-only ? rxchr: received character last character receiv ed if rxrdy is set. ? rxsynh: received sync 0: last character received is a data. 1: last character received is a command. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rxsynh ??????r x c h r 76543210 rxchr
841 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.14 usart transmit holding register name: us_thr address: 0x4002401c (0), 0x4002801c (1 ), 0x4002c01c (2), 0x4003001c (3), 0x4003401c (4) access: write-only ? txchr: character to be transmitted next character to be transm itted after the current character if txrdy is not set. ? txsynh: sync field to be transmitted 0: the next character sent is encoded as a data. start frame delimiter is data sync. 1: the next character sent is encoded as a command. start frame de limiter is command sync. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txsynh ??????t x c h r 76543210 txchr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 842 36.7.15 usart baud rate generator register name: us_brgr address: 0x40024020 (0), 0x40028020 (1), 0x4002c 020 (2), 0x40030020 (3), 0x40034020 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? . ? cd: clock divider ? fp: fractional part 0: fractional divider is disabled. 1?7: baud rate resolution, defined by fp 1/8. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????? f p 15 14 13 12 11 10 9 8 cd 76543210 cd cd usart_mode iso7816 usart_mode = iso7816 sync = 0 sync = 1 or usart_mode = spi (master or slave) over = 0 over = 1 0 baud rate clock disabled 1 to 65535 baud rate = selected clock / (16 cd) baud rate = selected clock / (8 cd) baud rate = selected clock / cd baud rate = selected clock / (fi_di_ratio cd)
843 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.16 usart receiver time-out register name: us_rtor address: 0x40024024 (0), 0x40028024 (1), 0x4002c 024 (2), 0x40030024 (3), 0x40034024 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? . ? to: time-out value 0: the receiver time-out is disabled. 1?65535: the receiver time-out is enabled and the time-out delay is to x bit period. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 to 76543210 to
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 844 36.7.17 usart transmitter timeguard register name: us_ttgr address: 0x40024028 (0), 0x40028028 (1), 0x4002c 028 (2), 0x40030028 (3), 0x40034028 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? . ? tg: timeguard value 0: the transmitter timeguard is disabled. 1?255: the transmitter timeguard is enabled and the timeguard delay is tg x bit period. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 tg
845 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.18 usart fi di ratio register name: us_fidi address: 0x40024040 (0), 0x40028040 (1), 0x4002c 040 (2), 0x40030040 (3), 0x40034040 (4) access: read/write ? fi_di_ratio: fi over di ratio value 0: if iso7816 mode is selected, the ba ud rate generator generates no signal. 1?2: do not use. 3? 2047: if iso7816 mode is selected, the baud rate is the clock provided on sck divided by fi_di_ratio. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????? f i _ d i _ r a t i o 76543210 fi_di_ratio this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? .
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 846 36.7.19 usart number of errors register name: us_ner address: 0x40024044 (0), 0x40028044 (1), 0x4002c 044 (2), 0x40030044 (3), 0x40034044 (4) access: read-only this register is relevant only if usart_mode = 0x4 or 0x6 in the ?usart mode register? on page 822 . ? nb_errors: number of errors total number of errors that occurred during an iso7816 transfer. this register autom atically clears when read. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 nb_errors
847 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.20 usart irda filter register name: us_if address: 0x4002404c (0), 0x4002804c (1 ), 0x4002c04c (2), 0x4003004c (3), 0x4003404c (4) access: read/write this register is relevant onl y if usart_mode = 0x8 in the ?usart mode register? on page 822 . ? irda_filter: irda filter the irda_filter value must be defi ned to meet the following criteria: t peripheral clock (irda_filter + 3) < 1.41 s 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 irda_filter this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? .
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 848 36.7.21 usart manchester configuration register name: us_man address: 0x40024050 (0), 0x40028050 (1), 0x4002c 050 (2), 0x40030050 (3), 0x40034050 (4) access: read/write ? tx_pl: transmitte r preamble length 0: the transmitter preamble pattern generation is disabled 1?15: the preamble length is tx_pl x bit period ? tx_pp: transmitter preamble pattern the following values assume that tx_mpol field is not set: ? tx_mpol: transmitter manchester polarity 0: logic zero is coded as a zero-to-one transition, logic one is coded as a one-to-zero transition. 1: logic zero is coded as a one-to-zero transition, logic one is coded as a zero-to-one transition. ? rx_pl: receiver preamble length 0: the receiver preamble pattern detection is disabled 1?15: the detected preamble length is rx_pl x bit period ? rx_pp: receiver preamble pattern detected the following values assume that rx_mpol field is not set: 31 30 29 28 27 26 25 24 ?d r i f to n er x _ m p o l? ? r x _ p p 23 22 21 20 19 18 17 16 ???? r x _ p l 15 14 13 12 11 10 9 8 ? ? ? tx_mpol ? ? tx_pp 76543210 ???? tx_pl this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? . value name description 0 all_one the preamble is composed of ?1?s 1 all_zero the preamble is composed of ?0?s 2 zero_one the preamble is composed of ?01?s 3 one_zero the preamble is composed of ?10?s value name description 00 all_one the preamble is composed of ?1?s
849 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? rx_mpol: receiver manchester polarity 0: logic zero is coded as a zero-to-one transition, logic one is coded as a one-to-zero transition. 1: logic zero is coded as a one-to-zero transition, logic one is coded as a zero-to-one transition. ? one: must be set to 1 bit 29 must always be set to 1 when programming the us_man register. ? drift: drift compensation 0: the usart cannot recover from an important clock drift 1: the usart can recover from clock drift. the 16x clock mode must be enabled. 01 all_zero the preamble is composed of ?0?s 10 zero_one the preamble is composed of ?01?s 11 one_zero the preamble is composed of ?10?s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 850 36.7.22 usart write protection mode register name: us_wpmr address: 0x400240e4 (0), 0x400280e4 (1), 0x4002c0 e4 (2), 0x400300e4 (3), 0x400340e4 (4) access: read/write ? wpen: write protection enable 0: disables the writ e protection if wpkey co rresponds to 0x555341 (?usa? in ascii). 1: enables the write protecti on if wpkey corres ponds to 0x555341 (?usa? in ascii). see section 36.6.9 ?register write protection? for the list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x555341 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
851 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 36.7.23 usart write protection status register name: us_wpsr address: 0x400240e8 (0), 0x400280e8 (1), 0x4002c0 e8 (2), 0x400300e8 (3), 0x400340e8 (4) access: read-only ? wpvs: write protection violation status 0: no write protection violation has oc curred since the last read of the us_wpsr. 1: a write protection violation has occurred since the last read of the us_wpsr. if this violation is an unauthorized attempt to write a protec ted register, the associ ated violation is repo rted into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at whic h a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 852 37. timer counter (tc) 37.1 description the timer counter (tc) includes three identical 16-bit timer counter channels. each channel can be independently programmed to perform a wide range of functions including frequency measurement, event counting, interval measurement, pulse generation, delay timing and pulse width modulation. each channel has three external clock inputs, five intern al clock inputs and two multi-purpose input/output signals which can be configured by the user. each channel drives an internal interrupt signal which can be programmed to generate processor interrupts. the timer counter (tc) embeds a quadrature decoder logic connected in front of the ti mers and driven by tioa0, tiob0 and tiob1 inputs. when enabled, the quadrature dec oder performs the input lines filtering, decoding of quadrature signals and connects to the timers/counters in order to read the position and speed of the motor through the user interface. the timer counter block has two global registers which act upon all tc channels: ? block control register (tc_bcr)?allo ws channels to be started simultaneously with the same instruction ? block mode register (tc_bmr)?defines the external cl ock inputs for each channel, allowing them to be chained table 37-1 gives the assignment of the device timer counter clock inputs common to timer counter 0 to 2. note: 1. when slow clock is selected for peripheral clock (c ss = 0 in pmc master clock register), timer_clock5 input is equivalent to peripheral clock. table 37-1. timer counter clock assignment name definition timer_clock1 mck/2 timer_clock2 mck/8 timer_clock3 mck/32 timer_clock4 mck/128 timer_clock5 (1) slck
853 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.2 embedded characteristics ? provides three 16-bit timer counter channels ? wide range of functions including: ? frequency measurement ? event counting ? interval measurement ? pulse generation ? delay timing ? pulse width modulation ? up/down capabilities ? quadrature decoder logic ? 2-bit gray up/down count for stepper motor ? each channel is user-configurable and contains: ? three external clock inputs ? five internal clock inputs ? two multi-purpose input/output si gnals acting as trigger event ? internal interrupt signal ? register write protection
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 854 37.3 block diagram figure 37-1. timer counter block diagram timer/counter channel 0 timer/counter channel 1 timer/counter channel 2 sync parallel i/o controller tc1xc1s tc0xc0s tc2xc2s int0 int1 int2 tioa0 tioa1 tioa2 tiob0 tiob1 tiob2 xc0 xc1 xc2 xc0 xc1 xc2 xc0 xc1 xc2 tclk0 tclk1 tclk2 tclk0 tclk1 tclk2 tclk0 tclk1 tclk2 tioa1 tioa2 tioa0 tioa2 tioa0 tioa1 interrupt controller tclk0 tclk1 tclk2 tioa0 tiob0 tioa1 tiob1 tioa2 tiob2 timer counter tioa tiob tioa tiob tioa tiob sync sync timer_clock2 timer_clock3 timer_clock4 timer_clock5 timer_clock1 table 37-2. signal name description block/channel signal name description channel signal xc0, xc1, xc2 external clock inputs tioa capture mode: timer counter input waveform mode: timer counter output tiob capture mode: timer counter input waveform mode: timer counter input/output int interrupt signal ou tput (internal signal) sync synchronization input signal (from configuration register)
855 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.4 pin name list 37.5 product dependencies 37.5.1 i/o lines the pins used for interfacing the compliant external dev ices may be multiplexed with pio lines. the programmer must first program the pio controllers to assign the tc pins to their peripheral functions. 37.5.2 power management the tc is clocked through the power management controller (pmc), thus the programmer must first configure the pmc to enable the timer counter clock. table 37-3. tc pin list pin name description type tclk0?tclk2 external clock input input tioa0?tioa2 i/o line a i/o tiob0?tiob2 i/o line b i/o table 37-4. i/o lines instance signal i/o line peripheral tc0 tclk0 pb4 b tc0 tclk1 pb9 a tc0 tclk2 pb12 a tc0 tioa0 pa13 b tc0 tioa1 pb7 a tc0 tioa2 pb10 a tc0 tiob0 pa14 b tc0 tiob1 pb8 a tc0 tiob2 pb11 a tc1 tclk3 pb26 a tc1 tclk4 pa17 b tc1 tclk5 pa19 b tc1 tioa3 pb24 a tc1 tioa4 pa15 b tc1 tioa5 pa18 b tc1 tiob3 pb25 a tc1 tiob4 pa16 b tc1 tiob5 pa20 b
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 856 37.5.3 interrupt the tc has an interrupt line connected to the interrupt controller (ic). handling the tc interrupt requires programming the ic before configuring the tc. 37.6 functional description 37.6.1 tc description the three channels of the timer counter are independent and identical in operation except when quadrature decoder is enabled. the registers for channel programming are listed in table 37-5 ?register mapping? . 37.6.2 16-bit counter each channel is organized around a 16-bit counter. the va lue of the counter is incremented at each positive edge of the selected clock. when th e counter has reached the value 2 16 -1 and passes to zero, an overflow occurs and the covfs bit in the tc stat us register (tc_sr) is set. the current value of the counter is accessible in real ti me by reading the tc counter value register (tc_cv). the counter can be reset by a trigger. in this case, the counter value passes to zero on the next valid edge of the selected clock. 37.6.3 clock selection at block level, input clock signals of each channel can either be connected to the exte rnal inputs tclk0, tclk1 or tclk2, or be connected to the inter nal i/o signals tioa0, tioa1 or tioa 2 for chaining by programming the tc block mode register (tc_bmr). see figure 37-2 ?clock chaining selection? . each channel can independently select an intern al or external clock source for its counter: ? internal clock signals: timer_clock1, ti mer_clock2, timer_clock3, timer_clock4, timer_clock5 ? external clock signals: xc0, xc1 or xc2 this selection is made by the tcclks bits in the tc channel mode register (tc_cmr). the selected clock can be inverted with the clki bit in the tc_cmr. this allows counting on the opposite edges of the clock. the burst function allows the clock to be validated when an external signal is high. the burst parameter in the tc_cmr defines this signal (none, xc0, xc1, xc2). see figure 37-3 ?clock selection? . note: in all cases, if an external clock is used, the duration of each of its levels must be longer than the peripheral clock period. the external clock frequency must be at least 2.5 times lower than the peripheral clock.
857 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 37-2. clock chaining selection figure 37-3. clock selection timer/counter channel 0 sync tc0xc0s tioa0 tiob0 xc0 xc1 = tclk1 xc2 = tclk2 tclk0 tioa1 tioa2 timer/counter channel 1 sync tc1xc1s tioa1 tiob1 xc0 = tclk0 xc1 xc2 = tclk2 tclk1 tioa0 tioa2 timer/counter channel 2 sync tc2xc2s tioa2 tiob2 xc0 = tclk0 xc1 = tclk1 xc2 tclk2 tioa0 tioa1 timer_clock1 timer_clock2 timer_clock3 timer_clock4 timer_clock5 xc0 xc1 xc2 tcclks clki synchronous edge detection burst peripheral clock 1 selected clock
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 858 37.6.4 clock control the clock of each counter can be controlled in two differ ent ways: it can be enabled/ disabled and started/stopped. see figure 37-4 . ? the clock can be enabled or disabled by the user with the clken and the clkdis commands in the tc channel control register (tc_ccr). in capture mode it ca n be disabled by an rb load event if ldbdis is set to 1 in the tc_cmr. in waveform mode, it can be disabled by an rc compare event if cpcdis is set to 1 in tc_cmr. when disabled, the start or the stop acti ons have no effect: only a clken command in the tc_ccr can re-enable the clock. when the clock is enabled, the clksta bit is set in the tc_sr. ? the clock can also be started or stopped: a trigger (software, synchro, external or compare) always starts the clock. the clock can be stopped by an rb load event in capture mode (ldbstop = 1 in tc_cmr) or a rc compare event in waveform mode (cpcstop = 1 in tc_cmr). the start and the stop commands have effect only if the clock is enabled. figure 37-4. clock control 37.6.5 tc operating modes each channel can independently operate in two different modes: ? capture mode provides measurement on signals. ? waveform mode provides wave generation. the tc operating mode is programmed with the wave bit in the tc channel mode register. in capture mode, tioa and tiob are configured as inputs. in waveform mode, tioa is always configured to be an output an d tiob is an output if it is not selected to be the external trigger. 37.6.6 trigger a trigger resets the counter and starts the counter clock. three types of tri ggers are common to both modes, and a fourth external trigger is available to each mode. regardless of the trigge r used, it will be taken into account at the follo wing active edge of t he selected clock. this means that the counter value can be read differently from zero just after a trigger, especially when a low frequency signal is selected as the clock. the following triggers are common to both modes: qs r s r q clksta clken clkdis stop event disable event counter clock selected clock trigger
859 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? software trigger: each channel has a software trigger, available by setting swtrg in tc_ccr. ? sync: each channel has a synchronization signal sync. when asserted, this signal has the same effect as a software trigger. the sync signals of all channels are asserted simultaneously by writing tc_bcr (block control) with sync set. ? compare rc trigger: rc is implemented in each channel and can provide a trigger when the counter value matches the rc value if cpctrg is set in the tc_cmr. the channel can also be configured to have an external tr igger. in capture mode, the ex ternal trigger signal can be selected between tioa and tiob. in waveform mode, an external event can be programmed on one of the following signals: tiob, xc0, xc1 or xc2. this external event can then be programmed to perform a trigger by setting bit enetrg in the tc_cmr. if an external trigger is used, the duration of the pulses must be longer than the peripheral clock period in order to be detected. 37.6.7 capture operating mode this mode is entered by clear ing the wave bit in the tc_cmr. capture mode allows the tc channel to perform measurements such as pulse timing, frequency, period, duty cycle and phase on tioa and tiob signa ls which are considered as inputs. figure 37-5 shows the configuration of the tc channel when programmed in capture mode. 37.6.8 capture registers a and b registers a and b (ra and rb) are used as capture registers. this means that they can be loaded with the counter value when a programmable event occurs on the signal tioa. the ldra field in the tc_cmr defines the tioa selected edge for the loading of register a, and the ldrb field defines the tioa selected edge for the loading of register b. ra is loaded only if it has not been loaded since the last trigger or if rb has been loaded since the last loading of ra. rb is loaded only if ra has been loaded since the last trigger or the last loading of rb. loading ra or rb before the read of the last value load ed sets the overrun error flag (lovrs bit) in the tc_sr. in this case, the old value is overwritten. 37.6.9 trigger conditions in addition to the sync signal, the software trigger and t he rc compare trigger, an external trigger can be defined. the abetrg bit in the tc_cmr selects tioa or tiob input signal as an external trigger . the external trigger edge selection parameter (etrgedg field in tc_cmr) defines the edge (rising, falling, or both) detected to generate an external trigger. if etrgedg = 0 (none), the external trigger is disabled.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 860 figure 37-5. capture mode timer_clock1 timer_clock2 timer_clock3 timer_clock4 timer_clock5 xc0 xc1 xc2 tcclks clki qs r s r q clksta clken clkdis burst tiob register c capture register a capture register b compare rc = counter abetrg swtrg etrgedg cpctrg tc1_imr trig ldrbs ldras etrgs tc1_sr lovrs covfs sync 1 mtiob tioa mtioa ldra ldbstop if ra is not loaded or rb is loaded if ra is loaded ldbdis cpcs int edge detector edge detector ldrb edge detector clk ovf reset timer/counter channel peripheral clock synchronous edge detection
861 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.6.10 waveform operating mode waveform operating mode is entered by setting the wave parameter in tc_cmr (channel mode register). in waveform operating mode the tc channel generates one or two pwm signals with the same frequency and independently programmable duty cycles, or generates different types of one-shot or repetitive pulses. in this mode, tioa is configured as an output and tiob is defined as an output if it is not used as an external event (eevt parameter in tc_cmr). figure 37-6 shows the configuration of the tc channel wh en programmed in waveform operating mode. 37.6.11 waveform selection depending on the wavsel parameter in tc_cmr (channel mode register), the behavior of tc_cv varies. with any selection, tc_ra, tc_rb and tc_rc can all be used as compare registers. ra compare is used to control the tioa output, rb co mpare is used to control the tiob output (if correctly configured) and rc compare is used to control tioa and/or tiob outputs.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 862 figure 37-6. waveform mode tcclks clki qs r s r q clksta clken clkdis cpcdis burst tiob register a register b register c compare ra = compare rb = compare rc = cpcstop counter eevt eevtedg sync swtrg enetrg wavsel tc1_imr trig acpc acpa aeevt aswtrg bcpc bcpb beevt bswtrg tioa mtioa tiob mtiob cpas covfs etrgs tc1_sr cpcs cpbs clk ovf reset output controller output controller int 1 edge detector timer/counter channel timer_clock1 timer_clock2 timer_clock3 timer_clock4 timer_clock5 xc0 xc1 xc2 wavsel peripheral clock synchronous edge detection
863 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.6.11.1wavsel = 00 when wavsel = 00, the value of tc _cv is incremented from 0 to 2 16 -1. once 2 16 -1 has been reached, the value of tc_cv is reset. increment ation of tc_cv starts again and the cycle continues. see figure 37-7 . an external event trigger or a software trigger can reset th e value of tc_cv. it is impo rtant to note that the trigger may occur at any time. see figure 37-8 . rc compare cannot be programmed to generate a trigger in this configuration. at t he same time, rc compare can stop the counter clock (cpcstop = 1 in tc_cmr ) and/or disable the count er clock (cpcdis = 1 in tc_cmr). figure 37-7. wavsel = 00 without trigger figure 37-8. wavsel= 00 with trigger time counter value r c r b r a tiob tioa counter cleared by compare match with 0xffff 0xffff waveform examples time counter value r c r b r a tiob tioa counter cleared by compare match with 0xffff 0xffff waveform examples counter cleared by trigger
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 864 37.6.11.2wavsel = 10 when wavsel = 10, the value of tc_cv is incremented fr om 0 to the value of rc, then automatically reset on a rc compare. once the value of tc_cv has been reset, it is then incremented and so on. see figure 37-9 . it is important to note that tc_cv can be reset at any time by an external event or a software trigger if both are programmed correctly. see figure 37-10 . in addition, rc compare can stop the counter clock (cpc stop = 1 in tc_cmr) and/or disable the counter clock (cpcdis = 1 in tc_cmr). figure 37-9. wavsel = 10 without trigger figure 37-10. wavsel = 10 with trigger time counter value r c r b r a tiob tioa counter cleared by compare match with rc waveform examples 2 n -1 (n = counter size) time counter value r c r b r a tiob tioa counter cleared by compare match with rc waveform examples counter cleared by trigger 2 n -1 (n = counter size)
865 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.6.11.3wavsel = 01 when wavsel = 01, the value of tc_cv is incremented from 0 to 2 16 -1. once 2 16 -1 is reached, the value of tc_cv is decremented to 0, then re-incremented to 2 16 -1 and so on. see figure 37-11 . a trigger such as an external event or a software trigger can modify tc_cv at any time. if a trigger occurs while tc_cv is incrementing, tc_cv then decrements. if a tr igger is received while tc _cv is decrementing, tc_cv then increments. see figure 37-12 . rc compare cannot be programmed to generate a trigger in this configuration. at the same time, rc compare can stop the counter cl ock (cpcstop = 1) and/or disable the counter clock (cpcdis = 1). figure 37-11. wavsel = 01 without trigger figure 37-12. wavsel = 01 with trigger time counter value r c r b r a tiob tioa counter decremented by compare match with 0xffff 0xffff waveform examples time counter value tiob tioa counter decremented by compare match with 0xffff 0xffff waveform examples counter decremented by trigger counter incremented by trigger r c r b r a
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 866 37.6.11.4wavsel = 11 when wavsel = 11, the value of tc_cv is incremented from 0 to rc. once rc is reached, th e value of tc_cv is decremented to 0, then re-incremented to rc and so on. see figure 37-13 . a trigger such as an external event or a software trigger can modify tc_cv at any time. if a trigger occurs while tc_cv is incrementing, tc_cv then decrements. if a tr igger is received while tc _cv is decrementing, tc_cv then increments. see figure 37-14 . rc compare can stop the counter clock (cpcstop = 1) and/or disable the counter clock (cpcdis = 1). figure 37-13. wavsel = 11 without trigger figure 37-14. wavsel = 11 with trigger time counter value r c r b r a tiob tioa counter decremented by compare match with rc waveform examples 2 n -1 (n = counter size) time counter value tiob tioa counter decremented by compare match with rc waveform examples counter decremented by trigger counter incremented by trigger r c r b r a 2 n -1 (n = counter size)
867 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.6.12 external event/trigger conditions an external event can be programmed to be detected on on e of the clock sources (xc0, xc1, xc2) or tiob. the external event selected can then be used as a trigger. the eevt parameter in tc_cmr selects the external trigger. the eevtedg parameter de fines the trigger edge for each of the possible extern al triggers (rising, falling or both). if e evtedg is cleared (none), no external event is defined. if tiob is defined as an external event signal (eevt = 0), tiob is no longer used as an output and the compare register b is not used to generate waveforms and subsequently no irqs. in this case the tc channel can only generate a waveform on tioa. when an external event is defined, it can be used as a trigger by setting bit enetrg in the tc_cmr. as in capture mode, the sync signal and the software trigger are also available as triggers. rc compare can also be used as a trigger de pending on the parameter wavsel. 37.6.13 output controller the output controller defines the outp ut level changes on tioa and tiob fo llowing an event. tiob control is used only if tiob is defined as output (not as an external event). the following events control tioa and tiob: software trigger, external event and rc compare. ra compare controls tioa and rb compare controls tiob. each of these events can be programmed to set, clear or toggle the output as defined in the corresponding parameter in tc_cmr. 37.6.14 quadrature decoder logic 37.6.14.1description the quadrature decoder logic is driven by tioa0, tiob0, tiob1 input pins and drives the timer/counter of channel 0 and 1. channel 2 can be used as a time base in case of speed measurement requirements (refer to figure 37-15 ?predefined connection of the quadrature decoder with timer counters? ). when writing a 0 to bit qden of the tc_bmr, th e quadrature decoder logic is totally transparent. tioa0 and tiob0 are to be driven by the two dedicat ed quadrature signals from a rotary sensor mounted on the shaft of the of f-chip motor. a third signal from the rotary sensor can be processed th rough pin tiob1 and is typically dedicated to be driven by an index signal if it is provided by the sensor. this signal is not requir ed to decode the quadrature signals pha, phb. field tcclks of tc_cmrx must be configured to select xc0 input (i.e., 0x101). fiel d tc0xc0s has no effect as soon as quadrature decoder is enabled. either speed or position/re volution can be measured. position channe l 0 accumulates the edges of pha, phb input signals giving a high accuracy on motor position whereas channel 1 accumulates the index pulses of the sensor, therefore the number of rotations. concatenatio n of both values provides a high level of precision on motion system position. in speed mode, position cannot be me asured but revolution can be measured. inputs from the rotary sensor can be filtered prior to down-stream processing. acco mmodation of input polarity, phase definition and other factors are configurable. interruptions can be generated on different events. a compare function (using tc_rc) is available on channel 0 (speed/position) or channel 1 (rotation) and can generate an interrupt by means of the cpcs flag in the tc_srx.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 868 figure 37-15. predefined connection of the quadrature decoder with timer counters timer/counter channel 0 1 xc0 tioa tiob timer/counter channel 1 1 xc0 tiob qden timer/counter channel 2 1 tiob0 xc0 1 1 speeden 1 xc0 quadrature decoder (filter + edge detect + qd) pha phb idx tioa0 tiob0 tiob1 tiob1 tioa0 index speed/position rotation speed time base reset pulse direction phedges qden
869 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.6.14.2input pre-processing input pre-processing consists of capab ilities to take into account rotary sensor factors such as polarities and phase definition followed by configurable digital filtering. each input can be negated and swapping pha, phb is also configurable. the maxfilt field in the tc_bmr is used to configure a minimum duration for which the pulse is stated as valid. when the filter is active, pulses wit h a duration lower than maxfilt +1 * t peripheral clock ns are not passed to down- stream logic. figure 37-16. input stage input filtering can efficiently remove spurious pulses that might be generated by the presence of particulate contamination on the optical or magnetic disk of the rotary sensor. spurious pulses can also occur in environments with high levels of electro-magnetic interference. or, simply if vibration occurs even when rotation is fully stopped and the shaft of the moto r is in such a position that the beginning of one of the reflective or magnetic bars on t he rotary sensor disk is aligned with the light or magnetic (hall) receiver cell of the rotary sensor. any vibration can make the pha, phb signals toggle for a short duration. 1 1 1 maxfilt pha phb idx tioa0 tiob0 tiob1 inva 1 invb 1 invidx swap 1 idxphb filter filter filter 1 direction and edge detection idx phedge dir input pre-processing maxfilt > 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 870 figure 37-17. filtering examples pha,b filter out peripheral clock maxfilt = 2 particulate contamination pha phb motor shaft stopped in such a position that rotary sensor cell is aligned with an edge of the disk rotation pha phb phb edge area due to system vibration resulting pha, phb electrical waveforms pha optical/magnetic disk strips stop phb mechanical shock on system vibration stop pha, phb electrical waveforms after filtering pha phb
871 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.6.14.3direction status and change detection after filtering, the quadrature signals are analyzed to extr act the rotation direction and edges of the two quadrature signals detected in order to be counted by timer/counter logic downstream. the direction status can be directly read at anytime in the tc_qisr. the polarity of the direction flag status depends on the configuration written in tc_bmr. inva, invb, invidx, swap modify the polarity of dir flag. any change in rotation direction is reported in the tc_qisr and can generate an interrupt. the direction change condition is reported as soon as two consecutive edges on a phase signal have sampled the same value on the other phase signal and there is an edge on the other signal. the tw o consecutive edges of one phase signal sampling the same value on other phase signal is not sufficient to declare a direction change, for the reason that particulate contamination may mask one or more reflective bars on the optica l or magnetic disk of the sensor. (refer to figure 37-18 ?rotation change detection? for waveforms.) figure 37-18. rotation change detection the direction change detection is disabled when qdtrans is set in the tc_bmr. in this case the dir flag report must not be used. a quadrature error is also reported by the quadrature deco der logic via the qerr flag in the tc_qisr. this error is reported if the time difference between two edges on pha, phb is lo wer than a predefined value. this pha phb direction change under normal conditions dir dirchg change condition report time no direction change due to particulate contamination masking a reflective bar pha phb dir dirchg spurious change condition (if detected in a simple way) same phase missing pulse
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 872 predefined value is configurable and co rresponds to (maxfilt + 1) * t peripheral clock ns. after being filtered there is no reason to have two edges closer than (maxfilt + 1) * t peripheral clock ns under normal mode of operation. figure 37-19. quadrature error detection maxfilt must be tuned accordin g to several factors such as the peripheral clock frequency, type of rotary sensor and rotation speed to be achieved. 37.6.14.4position and rotation measurement when the posen bit is set in the tc_bmr, the motor axis position is processed on channel 0 (by means of the pha, phb edge detections) and the number of motor revo lutions are recorded on channel 1 if the idx signal is provided on the tiob1 input. the position measurement can be read in the tc_cv0 register and the rotation measurement can be read in the tc_cv1 register. channel 0 and 1 must be configured in capture mode (wave = 0 in tc_cmr0). in parallel, the number of edges are accumulated on timer/counter channel 0 and can be read on the tc_cv0 register. therefore, the accurate position can be read on both tc_cv registers and concatenated to form a 32-bit word. the timer/counter channel 0 is cleared for each increment of idx count value. depending on the quadrature signals, the direction is decoded and allows to count up or down in timer/counter channels 0 and 1. the direction st atus is reported on tc_qisr. peripheral clock maxfilt = 2 pha phb a bnormally formatted optical disk strips (theoretical view) pha phb strip edge inaccurary due to disk etching/printing process resulting pha, phb electrical waveforms pha phb even with an abnorrmaly formatted disk, there is no occurence of pha, phb switching at the same time. qerr duration < maxfilt
873 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.6.14.5 speed measurement when speeden is set in the tc_bmr, the sp eed measure is enabl ed on channel 0. a time base must be defined on channel 2 by writing the tc_rc2 period register. channel 2 must be configured in waveform mode (wave bit set) in tc_c mr2. the wavsel field must be def ined with 0x10 to clear the counter by comparison and matching with tc_rc value. field acpc must be defined at 0x11 to toggle tioa output. this time base is automatically fed back to tioa of channel 0 when qden and speeden are set. channel 0 must be configur ed in capture mode (wave = 0 in tc_cmr 0). the abetrg bit of tc_cmr0 must be configured at 1 to select tioa as a trigger for this channel. edgtrg can be set to 0x01, to clear the counter on a risi ng edge of the tioa signal and field ldra must be set accordingly to 0x01, to load tc_ra0 at the same time as the counter is clear ed (ldrb must be set to 0x01). as a consequence, at the end of each time base period the differentiation required for the speed calculation is performed. the process must be started by configuring bits clken and swtrg in the tc_ccr. the speed can be read on field ra in tc_ra0. channel 1 can still be used to count th e number of revolutions of the motor. 37.6.14.6missing pulse detection and auto-correction the qdec is equipped with a circuitry which detects and corrects some errors that may result from contamination on optical disks or other materials producing the quadrature phase signals. the detection and autocorrection only wo rks if the count mode is configured for both phases (edgpha = 1 in tc_bmr) and is enabled (autoc = 1 in tc_bmr). if a pulse is missing on a phase signal, it is automatically detected and the pulse count reported in the cv field of the tc_cv0/1 is auto matically corrected. there is no detection if both phase signals are affected at the same location on the device providing the quadradure signals because the detection requires a valid phase signal to detect the contamination on the other phase signal. figure 37-20. detection and auto-correction of missing pulses if a quadrature device is undamaged, the number of puls es counted for a predefined pe riod of time must be the same with or without detection and auto-correction feature. therefore, if the measurem ent results differ, a contamination exists on the device producing the quadrature signals. pha phb missing pulse due to a contamination (dust, scratch, ...) not a change of direction detection 123 45 6 7 101213141516 corrections
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 874 this does not substitute the measurements of the number of pulses between two index pulses (if available) but provides a complementary method to detect damaged quadrature devices. when the device providing quadrature signals is severely damaged, potentially leading to a number of consecutive missing pulses greater than 1, the downstream processing may be affected. it is poss ible to define the maximum admissible number of consecutive missing pulses before issuing a missing pulse erro r flag (mpe in tc_qisr). the threshold triggering a mpe flag report can be configured in field maxcmp of the tc_bmr. if the field maxcmp is cleared, mpe never rises. the flag maxcmp can trigger an interrupt while the qdec is operating, thus providing a real time report of a potential problem on the quadrature device. 37.6.15 2-bit gray up/down counter for stepper motor each channel can be independently configured to generate a 2-bit gray count waveform on corresponding tioa, tiob outputs by means of the gcen bit in tc_smmrx. up or down count can be defined by writing bit down in tc_smmrx. it is mandatory to configure the channel in wave mode in the tc_cmr. the period of the counters can be programmed in tc_rcx. figure 37-21. 2-bit gray up/down counter 37.6.16 register write protection to prevent any single software error from corrupting tc behavior, certain registers in the address space can be write-protected by settin g the wpen bit in the tc write protection mode register (tc_wpmr). tioax tiobx downx tc_rcx wavex = gcenx =1 the following registers can be write-protected: ? tc block mode register ? tc channel mode register: capture mode ? tc channel mode register: waveform mode ? tc stepper motor mode register ? tc register a ? tc register b ? tc register c
875 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7 timer counter (tc) user interface notes: 1. channel index ranges from 0 to 2. 2. read-only if wave = 0 table 37-5. register mapping offset (1) register name access reset 0x00 + channel * 0x40 + 0x00 channel control register tc_ccr write-only ? 0x00 + channel * 0x40 + 0x04 channel mode register tc_cmr read/write 0 0x00 + channel * 0x40 + 0x08 stepper motor mode register tc_smmr read/write 0 0x00 + channel * 0x40 + 0x0c reserved ? ? ? 0x00 + channel * 0x40 + 0x10 counter value tc_cv read-only 0 0x00 + channel * 0x40 + 0x14 register a tc_ra read/write (2) 0 0x00 + channel * 0x40 + 0x18 register b tc_rb read/write (2) 0 0x00 + channel * 0x40 + 0x1c register c tc_rc read/write 0 0x00 + channel * 0x40 + 0x20 status register tc_sr read-only 0 0x00 + channel * 0x40 + 0x24 interrup t enable register tc_ier write-only ? 0x00 + channel * 0x40 + 0x28 interrup t disable register tc_idr write-only ? 0x00 + channel * 0x40 + 0x2c interrupt mask register tc_imr read-only 0 0xc0 block control register tc_bcr write-only ? 0xc4 block mode register tc_bmr read/write 0 0xc8 qdec interrupt enable register tc_qier write-only ? 0xcc qdec interrupt disable register tc_qidr write-only ? 0xd0 qdec interrupt mask register tc_qimr read-only 0 0xd4 qdec interrupt status register tc_qisr read-only 0 0xd8 reserved ? ? ? 0xe4 write protection mode register tc_wpmr read/write 0 0xe8?0xfc reserved ? ? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 876 37.7.1 tc channel control register name: tc_ccrx [x=0..2] address: 0x40010000 (0)[0], 0x40010040 (0)[1], 0x40010080 (0)[2] 0x40014000 (1)[0], 0x40014040 (1)[1], 0x40014080 (1)[2] access: write-only ? clken: counter clock enable command 0: no effect. 1: enables the clock if clkdis is not 1. ? clkdis: counter clock disable command 0: no effect. 1: disables the clock. ? swtrg: software trigger command 0: no effect. 1: a software trigger is performed: the co unter is reset and the clock is started. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????s w t r gc l k d i sc l k e n
877 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7.2 tc channel mode register: capture mode name: tc_cmrx [x=0..2] (wave = 0) address: 0x40010004 (0)[0], 0x40010044 (0)[1], 0x40010084 (0)[2] 0x40014004 (1)[0], 0x40014044 (1)[1], 0x40014084 (1)[2] access: read/write this register can only be written if the wpen bit is cleared in the tc write protection mode register . ? tcclks: clock selection ? clki: clock invert 0: counter is incremented on rising edge of the clock. 1: counter is incremented on falling edge of the clock. ? burst: burst signal selection ? ldbstop: counter clock stopped with rb loading 0: counter clock is not stopped when rb loading occurs. 1: counter clock is stopped when rb loading occurs. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???? l d r b l d r a 15 14 13 12 11 10 9 8 wave cpctrg ? ? ? abetrg etrgedg 76543210 ldbdis ldbstop burst clki tcclks value name description 0 timer_clock1 clock selected : internal timer_clock1 clock signal (from pmc) 1 timer_clock2 clock selected : internal timer_clock2 clock signal (from pmc) 2 timer_clock3 clock selected : internal timer_clock3 clock signal (from pmc) 3 timer_clock4 clock selected : internal timer_clock4 clock signal (from pmc) 4 timer_clock5 clock selected : internal timer_clock5 clock signal (from pmc) 5 xc0 clock selected: xc0 6 xc1 clock selected: xc1 7 xc2 clock selected: xc2 value name description 0 none the clock is not gated by an external signal. 1 xc0 xc0 is anded with the selected clock. 2 xc1 xc1 is anded with the selected clock. 3 xc2 xc2 is anded with the selected clock.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 878 ? ldbdis: counter clock disable with rb loading 0: counter clock is not disabl ed when rb loading occurs. 1: counter clock is disabled when rb loading occurs. ? etrgedg: external trigger edge selection ? abetrg: tioa or tiob ex ternal trigger selection 0: tiob is used as an external trigger. 1: tioa is used as an external trigger. ? cpctrg: rc compare trigger enable 0: rc compare has no effect on the counter and its clock. 1: rc compare resets the counter and starts the counter clock. ? wave: waveform mode 0: capture mode is enabled. 1: capture mode is disabled (waveform mode is enabled). ? ldra: ra loading edge selection ? ldrb: rb loading edge selection value name description 0 none the clock is not gated by an external signal. 1 rising rising edge 2 falling falling edge 3 edge each edge value name description 0 none none 1 rising rising edge of tioa 2 falling falling edge of tioa 3 edge each edge of tioa value name description 0 none none 1 rising rising edge of tioa 2 falling falling edge of tioa 3 edge each edge of tioa
879 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7.3 tc channel mode register: waveform mode name: tc_cmrx [x=0..2] (wave = 1) access: read/write this register can only be written if the wpen bit is cleared in the tc write protection mode register . ? tcclks: clock selection ? clki: clock invert 0: counter is incremented on rising edge of the clock. 1: counter is incremented on falling edge of the clock. ? burst: burst signal selection ? cpcstop: counter clock stopped with rc compare 0: counter clock is not stopped when counter reaches rc. 1: counter clock is stopped when counter reaches rc. 31 30 29 28 27 26 25 24 bswtrg beevt bcpc bcpb 23 22 21 20 19 18 17 16 aswtrg aeevt acpc acpa 15 14 13 12 11 10 9 8 wave wavsel enetrg eevt eevtedg 76543210 cpcdis cpcstop burst clki tcclks value name description 0 timer_clock1 clock selected: internal timer_clock1 clock signal (from pmc) 1 timer_clock2 clock selected: internal timer_clock2 clock signal (from pmc) 2 timer_clock3 clock selected: internal timer_clock3 clock signal (from pmc) 3 timer_clock4 clock selected: internal timer_clock4 clock signal (from pmc) 4 timer_clock5 clock selected: internal timer_clock5 clock signal (from pmc) 5 xc0 clock selected: xc0 6 xc1 clock selected: xc1 7 xc2 clock selected: xc2 value name description 0 none the clock is not gated by an external signal. 1 xc0 xc0 is anded with the selected clock. 2 xc1 xc1 is anded with the selected clock. 3 xc2 xc2 is anded with the selected clock.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 880 ? cpcdis: counter clock disable with rc compare 0: counter clock is not disabl ed when counter reaches rc. 1: counter clock is disabled when counter reaches rc. ? eevtedg: external event edge selection ? eevt: external event selection signal selected as external event. note: 1. if tiob is chosen as the external event signal, it is configured as an input and no longer generates waveforms and subsequently no irqs. ? enetrg: external event trigger enable 0: the external event has no effect on the counter and its clock. 1: the external event resets the counter and starts the counter clock. note: whatever the value programmed in enetrg, the selected external event only controls the tioa output and tiob if not used as input (trigger event inpu t or other input used). ? wavsel: waveform selection ? wave: waveform mode 0: waveform mode is disabled (capture mode is enabled). 1: waveform mode is enabled. value name description 0 none none 1 rising rising edge 2 falling falling edge 3 edge each edge value name description tiob direction 0 tiob tiob (1) input 1 xc0 xc0 output 2 xc1 xc1 output 3 xc2 xc2 output value name description 0 up up mode without automatic trigger on rc compare 1 updown updown mode without automatic trigger on rc compare 2 up_rc up mode with automatic trigger on rc compare 3 updown_rc updown mode with automatic trigger on rc compare
881 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? acpa: ra compare effect on tioa ? acpc: rc compare effect on tioa ? aeevt: external event effect on tioa ? aswtrg: software trigger effect on tioa ? bcpb: rb compare effect on tiob ? bcpc: rc compare effect on tiob value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 882 ? beevt: external event effect on tiob ? bswtrg: software trigger effect on tiob value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle
883 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7.4 tc stepper motor mode register name: tc_smmrx [x=0..2] address: 0x40010008 (0)[0], 0x40010048 (0)[1], 0x40010088 (0)[2] 0x40014008 (1)[0], 0x40014048 (1)[1], 0x40014088 (1)[2] access: read/write this register can only be written if the wpen bit is cleared in the tc write protection mode register . ? gcen: gray count enable 0: tioax [x=0..2] and tiobx [x=0..2] are driven by internal counter of channel x. 1: tioax [x=0..2] and ti obx [x=0..2] are driven by a 2-bit gray counter. ? down: down count 0: up counter. 1: down counter. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????d o w ng c e n
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 884 37.7.5 tc counter value register name: tc_cvx [x=0..2] address: 0x40010010 (0)[0], 0x40010050 (0)[1], 0x40010090 (0)[2] 0x40014010 (1)[0], 0x40014050 (1)[1], 0x40014090 (1)[2] access: read-only ? cv: counter value cv contains the counter value in real time. 31 30 29 28 27 26 25 24 cv 23 22 21 20 19 18 17 16 cv 15 14 13 12 11 10 9 8 cv 76543210 cv
885 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7.6 tc register a name: tc_rax [x=0..2] address: 0x40010014 (0)[0], 0x40010054 (0)[1], 0x40010094 (0)[2] 0x40014014 (1)[0], 0x40014054 (1)[1], 0x40014094 (1)[2] access: read-only if wave = 0, read/write if wave = 1 this register can only be written if the wpen bit is cleared in the tc write protection mode register . ? ra: register a ra contains the register a value in real time. 31 30 29 28 27 26 25 24 ra 23 22 21 20 19 18 17 16 ra 15 14 13 12 11 10 9 8 ra 76543210 ra
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 886 37.7.7 tc register b name: tc_rbx [x=0..2] address: 0x40010018 (0)[0], 0x40010058 (0)[1], 0x40010098 (0)[2] 0x40014018 (1)[0], 0x40014058 (1)[1], 0x40014098 (1)[2] access: read-only if wave = 0, read/write if wave = 1 this register can only be written if the wpen bit is cleared in the tc write protection mode register . ? rb: register b rb contains the register b value in real time. 31 30 29 28 27 26 25 24 rb 23 22 21 20 19 18 17 16 rb 15 14 13 12 11 10 9 8 rb 76543210 rb
887 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7.8 tc register c name: tc_rcx [x=0..2] address: 0x4001001c (0)[0], 0x4001005c (0)[1], 0x4001009c (0)[2] 0x4001401c (1)[0], 0x4001405c (1)[1], 0x4001409c (1)[2] access: read/write this register can only be written if the wpen bit is cleared in the tc write protection mode register . ? rc: register c rc contains the register c value in real time. 31 30 29 28 27 26 25 24 rc 23 22 21 20 19 18 17 16 rc 15 14 13 12 11 10 9 8 rc 76543210 rc
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 888 37.7.9 tc status register name: tc_srx [x=0..2] address: 0x40010020 (0)[0], 0x40010060 (0)[1], 0x400100a0 (0)[2] 0x40014020 (1)[0], 0x40014060 (1)[1], 0x400140a0 (1)[2] access: read-only ? covfs: counter overflow status 0: no counter overflow has occurred since the last read of the status register. 1: a counter overflow has occurred since the last read of the status register. ? lovrs: load overrun status 0: load overrun has not occurred since the last read of the status register or wave = 1. 1: ra or rb have been loaded at least twice without any read of the corresponding register since the last read of the sta- tus register, if wave = 0. ? cpas: ra compare status 0: ra compare has not occurred since the last read of the status register or wave = 0. 1: ra compare has occurred since the last read of the status register, if wave = 1. ? cpbs: rb compare status 0: rb compare has not occurred since the last read of the status register or wave = 0. 1: rb compare has occurred since the last read of the status register, if wave = 1. ? cpcs: rc compare status 0: rc compare has not occurred since th e last read of the status register. 1: rc compare has occurred since th e last read of the status register. ? ldras: ra loading status 0: ra load has not occurred si nce the last read of the st atus register or wave = 1. 1: ra load has occurred since the last re ad of the status register, if wave = 0. ? ldrbs: rb loading status 0: rb load has not occurred si nce the last read of the st atus register or wave = 1. 1: rb load has occurred since the last re ad of the status register, if wave = 0. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ?????m t i o bm t i o ac l k s t a 15 14 13 12 11 10 9 8 ???????? 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
889 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? etrgs: external trigger status 0: external trigger has not occurred sinc e the last read of the status register. 1: external trigger has occurred since the last read of the status register. ? clksta: clock enabling status 0: clock is disabled. 1: clock is enabled. ? mtioa: tioa mirror 0: tioa is low. if wave = 0, this mean s that tioa pin is low. if wave = 1, this means that tioa is driven low. 1: tioa is high. if wave = 0, this mean s that tioa pin is high. if wave = 1, this means that ti oa is driven high. ? mtiob: tiob mirror 0: tiob is low. if wave = 0, this mean s that tiob pin is low. if wave = 1, this means that tiob is driven low. 1: tiob is high. if wave = 0, this mean s that tiob pin is high. if wave = 1, this means that ti ob is driven high.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 890 37.7.10 tc interrupt enable register name: tc_ierx [x=0..2] address: 0x40010024 (0)[0], 0x40010064 (0)[1], 0x400100a4 (0)[2] 0x40014024 (1)[0], 0x40014064 (1)[1], 0x400140a4 (1)[2] access: write-only ? covfs: counter overflow 0: no effect. 1: enables the counter overflow interrupt. ? lovrs: load overrun 0: no effect. 1: enables the load overrun interrupt. ? cpas: ra compare 0: no effect. 1: enables the ra compare interrupt. ? cpbs: rb compare 0: no effect. 1: enables the rb compare interrupt. ? cpcs: rc compare 0: no effect. 1: enables the rc compare interrupt. ? ldras: ra loading 0: no effect. 1: enables the ra load interrupt. ? ldrbs: rb loading 0: no effect. 1: enables the rb load interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
891 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? etrgs: external trigger 0: no effect. 1: enables the exter nal trigger interrupt.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 892 37.7.11 tc interrupt disable register name: tc_idrx [x=0..2] address: 0x40010028 (0)[0], 0x40010068 (0)[1], 0x400100a8 (0)[2] 0x40014028 (1)[0], 0x40014068 (1)[1], 0x400140a8 (1)[2] access: write-only ? covfs: counter overflow 0: no effect. 1: disables the counte r overflow interrupt. ? lovrs: load overrun 0: no effect. 1: disables the load overrun interr upt (if wave = 0). ? cpas: ra compare 0: no effect. 1: disables the ra compare interrupt (if wave = 1). ? cpbs: rb compare 0: no effect. 1: disables the rb compare interrupt (if wave = 1). ? cpcs: rc compare 0: no effect. 1: disables the rc compare interrupt. ? ldras: ra loading 0: no effect. 1: disables the ra load interrupt (if wave = 0). ? ldrbs: rb loading 0: no effect. 1: disables the rb load interrupt (if wave = 0). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
893 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? etrgs: external trigger 0: no effect. 1: disables the external trigger interrupt.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 894 37.7.12 tc interrupt mask register name: tc_imrx [x=0..2] address: 0x4001002c (0)[0], 0x4001006c (0)[1], 0x400100ac (0)[2] 0x4001402c (1)[0], 0x4001406c (1)[1], 0x400140ac (1)[2] access: read-only ? covfs: counter overflow 0: the counter overflow interrupt is disabled. 1: the counter overflow interrupt is enabled. ? lovrs: load overrun 0: the load overrun interrupt is disabled. 1: the load overrun interrupt is enabled. ? cpas: ra compare 0: the ra compare interrupt is disabled. 1: the ra compare in terrupt is enabled. ? cpbs: rb compare 0: the rb compare interrupt is disabled. 1: the rb compare in terrupt is enabled. ? cpcs: rc compare 0: the rc compare interrupt is disabled. 1: the rc compare interrupt is enabled. ? ldras: ra loading 0: the load ra interrupt is disabled. 1: the load ra interrupt is enabled. ? ldrbs: rb loading 0: the load rb interrupt is disabled. 1: the load rb interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
895 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? etrgs: external trigger 0: the external trigger interrupt is disabled. 1: the external trigger interrupt is enabled.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 896 37.7.13 tc block co ntrol register name: tc_bcr address: 0x400100c0 (0), 0x400140c0 (1) access: write-only ? sync: synchro command 0: no effect. 1: asserts the sync signal which generates a software trigger simultaneously fo r each of the channels. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????s y n c
897 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7.14 tc block mode register name: tc_bmr address: 0x400100c4 (0), 0x400140c4 (1) access: read/write this register can only be written if the wpen bit is cleared in the tc write protection mode register . ? tc0xc0s: external clock signal 0 selection ? tc1xc1s: external clock signal 1 selection ? tc2xc2s: external clock signal 2 selection ? qden: quadrature decoder enabled 0: disabled. 1: enables the quadrature decoder logic (filt er, edge detection and quadrature decoding). quadrature decoding (direction change ) can be disabled using qdtrans bit. one of the posen or speeden bits must be also enabled. 31 30 29 28 27 26 25 24 ? ? maxcmp maxfilt 23 22 21 20 19 18 17 16 maxfilt ? autoc idxphb swap 15 14 13 12 11 10 9 8 invidx invb inva edgpha qdtrans speeden posen qden 76543210 ? ? tc2xc2s tc1xc1s tc0xc0s value name description 0 tclk0 signal connected to xc0: tclk0 1? r e s e r v e d 2 tioa1 signal connected to xc0: tioa1 3 tioa2 signal connected to xc0: tioa2 value name description 0 tclk1 signal connected to xc1: tclk1 1? r e s e r v e d 2 tioa0 signal connected to xc1: tioa0 3 tioa2 signal connected to xc1: tioa2 value name description 0 tclk2 signal connected to xc2: tclk2 1? r e s e r v e d 2 tioa0 signal connected to xc2: tioa0 3 tioa1 signal connected to xc2: tioa1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 898 ? posen: position enabled 0: disable position. 1: enables the position measure on channel 0 and 1. ? speeden: speed enabled 0: disabled. 1: enables the speed measure on channel 0, the time base being provided by channel 2. ? qdtrans: quadrature decoding transparent 0: full quadrature decoding logic is active (direction change detected). 1: quadrature decoding logic is inactive (direction change inactive) but input filtering and edge detection are performed. ? edgpha: edge on pha count mode 0: edges are detected on pha only. 1: edges are detected on both pha and phb. ? inva: inverted pha 0: pha (tioa0) is directly driving quadrature decoder logic. 1: pha is inverted before driving quadrature decoder logic. ? invb: inverted phb 0: phb (tiob0) is directly driving quadrature decoder logic. 1: phb is inverted before driving quadrature decoder logic. ? swap: swap pha and phb 0: no swap between pha and phb. 1: swap pha and phb internally, prior to driving quadrature decoder logic. ? invidx: inverted index 0: idx (tioa1) is directly driving quadrature logic. 1: idx is inverted before driving quadrature logic. ? idxphb: index pin is phb pin 0: idx pin of the rotary sensor must drive tioa1. 1: idx pin of the rotary sensor must drive tiob0. ? autoc: auto-correction of missing pulses 0 (disabled): the detection and auto-correction function is disabled. 1 (enabled): the detection and au to-correction function is enabled. ? maxfilt: maximum filter 1?63: defines the f iltering capabilities. pulses with a period shorter than maxfilt+1 peripheral clock cycles are discarded.
899 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? maxcmp: maximum consecutive missing pulses 0: the flag mpe in tc_qisr never rises. 1?15: defines the number of consecutive missing pulses before a flag report.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 900 37.7.15 tc qdec interrupt enable register name: tc_qier address: 0x400100c8 (0), 0x400140c8 (1) access: write-only ? idx: index 0: no effect. 1: enables the interrupt when a rising edge occurs on idx input. ? dirchg: direction change 0: no effect. 1: enables the interrupt when a change on rotation direction is detected. ? qerr: quadrature error 0: no effect. 1: enables the interrupt when a quadrature error occurs on pha, phb. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????q e r rd i r c h gi d x
901 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7.16 tc qdec interrupt disable register name: tc_qidr address: 0x400100cc (0), 0x400140cc (1) access: write-only ? idx: index 0: no effect. 1: disables the interrupt when a rising edge occurs on idx input. ? dirchg: direction change 0: no effect. 1: disables the interrupt when a chan ge on rotation direction is detected. ? qerr: quadrature error 0: no effect. 1: disables the interrupt when a quadrature error occurs on pha, phb. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????q e r rd i r c h gi d x
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 902 37.7.17 tc qdec interrupt mask register name: tc_qimr address: 0x400100d0 (0), 0x400140d0 (1) access: read-only ? idx: index 0: the interrupt on idx input is disabled. 1: the interrupt on idx input is enabled. ? dirchg: direction change 0: the interrupt on rotation direction change is disabled. 1: the interrupt on rotation direction change is enabled. ? qerr: quadrature error 0: the interrupt on quadrature error is disabled. 1: the interrupt on quadrature error is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????q e r rd i r c h gi d x
903 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 37.7.18 tc qdec interrupt status register name: tc_qisr address: 0x400100d4 (0), 0x400140d4 (1) access: read-only ? idx: index 0: no index input change since the last read of tc_qisr. 1: the idx input has changed since the last read of tc_qisr. ? dirchg: direction change 0: no change on rotation direction since the last read of tc_qisr. 1: the rotation direction changed since the last read of tc_qisr. ? qerr: quadrature error 0: no quadrature error since the last read of tc_qisr. 1: a quadrature error occurred si nce the last read of tc_qisr. ?dir: direction returns an image of the actual rotation direction. ? mpe: consecutive missing pulse error 0: the number of consecutive missing pu lses has not reached the maximum value s pecified in maxmp since the last read of tc_qisr. 1: an occurrence of maxcmp consec utive missing pulses has been detec ted since the last read of tc_qisr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????d i r 76543210 ????m p eq e r rd i r c h gi d x
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 904 37.7.19 tc write protection mode register name: tc_wpmr address: 0x400100e4 (0), 0x400140e4 (1) access: read/write ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x54494d (? tim? in ascii). 1: enables the write protecti on if wpkey corres ponds to 0x54494d (?tim? in ascii). see section 37.6.16 ?register write protection? for list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x54494d passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
905 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38. pulse width modulation controller (pwm) 38.1 description the pwm macrocell controls several channels indep endently. each channel controls one square output waveform. characteristics of the output waveform such as period, duty-cycle and polarity are configurable through the user interface. each channel selects and uses one of the clocks provided by t he clock generator. the clock generator provides several clocks resulting from the division of the pwm macrocell master clock. all pwm macrocell accesses are made through apb mapped registers. channels can be synchronized, to generate non overlapped waveforms. all channels in tegrate a double buffering system in order to prevent an unexpected output wave form while modifying the period or the duty-cycle. 38.2 embedded characteristics ? 4 channels ? one 16-bit counter per channel ? common clock generator providi ng thirteen dif ferent clocks ? a modulo n counter providing eleven clocks ? two independent linear dividers working on modulo n counter outputs ? independent channels ? independent enable disable command for each channel ? independent clock selection for each channel ? independent period and duty cycle for each channel ? double buffering of period or duty cycle for each channel ? programmable selection of the output waveform polarity for each channel ? programmable center or left aligned output waveform for each channel block diagram
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 906 38.3 block diagram figure 38-1. pulse width modulati on controller block diagram 38.4 i/o lines description each channel outputs one waveform on one external i/o line. 38.5 product dependencies 38.5.1 i/o lines the pins used for interfacing the pwm may be multiple xed with pio lines. the programmer must first program the pio controller to assign the desired pwm pins to their pe ripheral function. if i/o lines of the pwm are not used by the application, they can be used for other purposes by the pio controller. pwm controller apb pwmx pwmx pwmx channel update duty cycle counter pwm0 channel pio interrupt controller pmc mck clock generator apb interface interrupt generator clock selector period update duty cycle counter clock selector period pwm0 pwm0 comparator comparator table 38-1. i/o line description name description type pwmx pwm waveform output for channel x output
907 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 all of the pwm outputs may or may not be enabled. if an application requires only four channels, then only four pio lines will be assi gned to pwm outputs. 38.5.2 power management the pwm is not continuously clocked. the progra mmer must first enable the pwm clock in the power management controller (pmc) before using the pwm. however, if the application does not require pwm operations, the pwm clock can be stopped when not needed and be restarted later. in this case, the pwm will resume its operations where it left off. all the pwm registers except pwm_ cdty and pwm_cprd can be read without the pwm peripheral clock enabled. all the registers can be written without the peripheral clock enabled. 38.5.3 interrupt sources the pwm interrupt line is connected on one of the inter nal sources of the interrupt controller. using the pwm interrupt requires the interrupt controller to be progr ammed first. note that it is not recommended to use the pwm interrupt line in edge sensitive mode. table 38-2. i/o lines instance signal i/o line peripheral pwm pwm0 pc0 b pwm pwm0 pc6 a pwm pwm1 pc1 b pwm pwm1 pc7 a pwm pwm2 pc2 b pwm pwm2 pc8 a pwm pwm3 pc3 b pwm pwm3 pc9 a table 38-3. peripheral ids instance id pwm 41
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 908 38.6 functional description the pwm macrocell is primarily composed of a clock generator module and 4 channels. ? clocked by the system clock, mck, the clock generator module provides 13 clocks. ? each channel can independently choose one of the clock generator outputs. ? each channel generates an output waveform with attributes that can be defined independently for each channel through the user interface registers. 38.6.1 pwm clock generator figure 38-2. functional view of the clock generator block diagram caution: before using the pwm macrocell, the programmer must first enable the pwm clock in the power management controller (pmc). the pwm macrocell master clock, mck, is divided in the clock generator module to provide different clocks available for all channels. each channel can in dependently select one of the divided clocks. the clock generator is divided in three blocks: ? a modulo n counter which provides 11 clocks: f mck , f mck /2, f mck /4, f mck /8, f mck /16, f mck /32, f mck /64, f mck /128, f mck /256, f mck /512, f mck /1024 ? two linear dividers (1, 1/2, 1/ 3,... 1/255) that provide two se parate clocks: clka and clkb modulo n counter mck mck/2 mck/4 mck/16 mck/32 mck/64 mck/8 divider a clka diva pwm_mr mck mck/128 mck/256 mck/512 mck/1024 prea divider b clkb divb pwm_mr preb
909 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 each linear divider can independently divide one of the cl ocks of the modulo n counter. the selection of the clock to be divided is made according to the prea (preb) field of the pwm mode register (pwm_mr). the resulting clock clka (clkb) is the clock selected divided by diva (divb) field value in the pwm mode register (pwm_mr). after a reset of the pwm controller, diva (divb) and pr ea (preb) in the pwm mode register are set to 0. this implies that after reset clka (clkb) are turned off. at reset, all clocks provided by the modulo n counter are tu rned off except clock ?clk?. this situation is also true when the pwm master clock is turned off through the power management controller. 38.6.2 pwm channel 38.6.2.1 block diagram figure 38-3. functional view of the channel block diagram each of the 4 channels is composed of three blocks: ? a clock selector which selects one of the clocks provided by the clock generator described in section 38.6.1 ?pwm clock generator? on page 908 . ? an internal counter cl ocked by the output of the clock selector. this internal counter is incremented or decremented according to the channel configuration and comparators events. the size of the internal counter is 16 bits. ? a comparator used to generate events according to the internal counter value. it also computes the pwmx output waveform according to the configuration. 38.6.2.2 waveform properties the different properties of output waveforms are: ? the internal clock selection . the internal channel counter is clocke d by one of the clocks provided by the clock generator described in the previous section. this channel parameter is defined in the cpre field of the pwm_cmrx register. this field is reset at 0. ? the waveform period . this channel parameter is defined in the cprd field of the pwm_cprdx register. - if the waveform is left aligned, then the output wa veform period depends on the counter source clock and can be calculated: by using the master clock (mck) divided by an x given prescaler value (with x being 1, 2, 4, 8, 16, 32 , 64, 128, 256, 51 2, or 1024), th e resulting period formula will be: by using a master clock divided by one of both diva or divb divider, the formula becomes, respectively: or if the waveform is center aligned then the output wa veform period depends on the counter source clock and compar ator pwmx output w a veform intern al counter clock selector inputs from clock gener ator inputs from apb bus channel xcprd () mck ------------------------------- x * cprd * diva () mck ---------------------------------------------- - x * cprd * divb () mck ---------------------------------------------- -
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 910 can be calculated: by using the master clock (mck) divided by an x given prescaler value (with x being 1, 2, 4, 8, 16, 32 , 64, 128, 256, 51 2, or 1024). the result ing period formula will be: by using a master clock divided by one of both diva or divb divider, the formula becomes, respectively: or ? the waveform duty cycle . this channel parameter is defined in the cdty field of the pwm_cdtyx register. if the waveform is left aligned then: if the waveform is center aligned, then: ? the waveform polarity. at the beginning of the period, the signal ca n be at high or low level. this property is defined in the cpol field of the pwm_cmrx regist er. by default the signal starts by a low level. ? the waveform alignment . the output waveform can be left or center aligned. center aligned waveforms can be used to generate non overlapped waveforms. this property is defined in the calg field of the pwm_cmrx register. the default mode is left aligned. figure 38-4. non overlapped center aligned waveforms note: 1. see figure 38-5 on page 911 for a detailed description of center aligned waveforms. when center aligned, the internal channel counter increases up to cprd and.decreases down to 0. this ends the period. when left aligned, the internal channel counter increa ses up to cprd and is reset. this ends the period. thus, for the same cprd value, the period for a center aligned channel is twice the period for a left aligned channel. waveforms are fixed at 0 when: ? cdty = cprd and cpol = 0 ? cdty = 0 and cpol = 1 waveforms are fixed at 1 (once the channel is enabled) when: ? cdty = 0 and cpol = 0 2 xcprd () mck ---------------------------------------- 2*x * cprd * diva () mck ----------------------------------------------------- - 2*x * cprd * divb () mck ----------------------------------------------------- - duty cycle period 1 fchannel_x_clock cdty ? ? () period --------------------------------------------------------------------------------------------------- - = duty cycle period 2 ? () cdty ? ? ()) period 2 ? () = pwm0 pwm1 period no overlap
911 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? cdty = cprd and cpol = 1 the waveform polarity must be set before enabling the ch annel. this immediately affects the channel output level. changes on channel polarity are not taken into account while the channel is enabled. figure 38-5. waveform properties pwm_mckx chidx(pwm_sr) center aligned cprd(pwm_cprdx) cdty(pwm_cdtyx) pwm_ccntx output waveform pwmx cpol(pwm_cmrx) = 0 output waveform pwmx cpol(pwm_cmrx) = 1 chidx(pwm_isr) left aligned cprd(pwm_cprdx) cdty(pwm_cdtyx) pwm_ccntx output waveform pwmx cpol(pwm_cmrx) = 0 output waveform pwmx cpol(pwm_cmrx) = 1 chidx(pwm_isr) calg(pwm_cmrx) = 0 calg(pwm_cmrx) = 1 period period chidx(pwm_ena) chidx(pwm_dis)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 912 38.6.3 pwm controller operations 38.6.3.1 initialization before enabling the output channel, this channel must have been configured by the software application: ? configuration of the clock generator if diva and divb are required ? selection of the clock for each channel (cpre field in the pwm_cmrx register) ? configuration of the waveform alignment for each channel (calg field in the pwm_cmrx register) ? configuration of the period for each channel (cprd in the pwm_cprdx register ). writing in pwm_cprdx register is possible while the channel is disabled. after validation of the channel, the user must use pwm_cupdx register to update pwm_cprdx as explained below. ? configuration of the duty cycle for each channel (cdty in the pwm_cdtyx register). writing in pwm_cdtyx register is possible wh ile the channel is disabled. after validation of the channel, the user must use pwm_cupdx register to upd ate pwm_cdtyx as explained below. ? configuration of the output waveform polarity for each channel (cpol in the pwm_cmrx register) ? enable interrupts (writing chidx in the pwm_ier register) ? enable the pwm channel (writing chidx in the pwm_ena register) it is possible to synchron ize different channels by enab ling them at the same ti me by means of writing simultaneously several chidx bi ts in the pwm_ena register. ? in such a situation, all channels may have the same clock selector configuration and the same period specified. 38.6.3.2 source clock selection criteria the large number of source clocks can make selection di fficult. the relationship between the value in the period register (pwm_cprdx) and the duty cycle register (pwm_cdtyx) can help the user in choosing. the event number written in the period register gives the pwm accuracy. the duty cycle quantum cannot be lower than 1/pwm_cprdx value. the higher the value of pwm_cprdx, the greater the pwm accuracy. for example, if the user sets 15 (in decimal) in pwm_cprd x, the user is able to set a value between 1 up to 14 in pwm_cdtyx register. the resulting duty cycle quantu m cannot be lower than 1/15 of the pwm period. 38.6.3.3 changing the duty cycle or the period it is possible to modu late the output waveform duty cycle or period. to prevent unexpected output waveform, the user mu st use the update register (pwm_cupdx) to change waveform parameters while t he channel is still enabled. the user can writ e a new period value or duty cycle value in the update register (pwm_cupdx). this register hol ds the new value until the end of the current cycle and updates the value for the next cycle. depending on th e cpd field in the pwm_cmrx register, pwm_cupdx either updates pwm_cprdx or pwm_cdtyx. note that even if the update register is used, the period must not be smaller than the duty cycle.
913 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 38-6. synchronized period or duty cycle update to prevent overwriting the pwm_cupdx by software, the user can use status events in order to synchronize his software. two methods are possible. in both, the user must enable the dedicated interrupt in pwm_ier at pwm controller level. the first method (polling method) consists of reading the re levant status bit in pwm_isr register according to the enabled channel(s). see figure 38-7 . the second method uses an interrupt service routine associated with the pwm channel. note: reading the pwm_isr register automatically clears chidx flags. figure 38-7. polling method note: polarity and alignment can be modi fied only when the channel is disabled. 38.6.3.4 interrupts depending on the interrupt mask in the pwm_imr regi ster, an interrupt is generated at the end of the corresponding channel period. the interrupt remains active until a read operation in the pwm_isr register occurs. pwm_cupdx value pwm_cprdx pwm_cdtyx end of cycle pwm_cmrx. cpd user's writing 1 0 writing in pwm_cupdx the last write has been taken into account chidx = 1 writing in cpd field update of the period or duty cycle pwm_isr read acknowledgement and clear previous register state yes
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 914 a channel interrupt is enabled by setting the corresponding bit in the pwm_ier register. a channel interrupt is disabled by setting the corresponding bit in the pwm_idr register.
915 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38.7 pulse width modulation cont roller (pwm) user interface 2. some registers are indexed with ?ch_num? index ranging from 0 to 3. table 38-4. register mapping (2) offset register name access reset 0x00 pwm mode register pwm_mr read-write 0 0x04 pwm enable register pwm_ena write-only - 0x08 pwm disable register pwm_dis write-only - 0x0c pwm status register pwm_sr read-only 0 0x10 pwm interrupt enable register pwm_ier write-only - 0x14 pwm interrupt disable register pwm_idr write-only - 0x18 pwm interrupt mask register pwm_imr read-only 0 0x1c pwm interrupt status register pwm_isr read-only 0 0x20 - 0xfc reserved ? ? ? 0x100 - 0x1fc reserved 0x200 + ch_num * 0x20 + 0x00 pwm channel mode register pwm_cmr read-write 0x0 0x200 + ch_num * 0x20 + 0x04 pwm channel duty cycle register pwm_cdty read-write 0x0 0x200 + ch_num * 0x20 + 0x08 pwm channel period register pwm_cprd read-write 0x0 0x200 + ch_num * 0x20 + 0x0c pwm channel counter register pwm_ccnt read-only 0x0 0x200 + ch_num * 0x20 + 0x10 pwm channel update register pwm_cupd write-only -
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 916 38.7.1 pwm mode register name: pwm_mr address: 0x48008000 access: read/write ? diva, divb: clka, clkb divide factor ? prea, preb values which are not listed in the table must be considered as ?reserved?. 31 30 29 28 27 26 25 24 ???? p r e b 23 22 21 20 19 18 17 16 divb 15 14 13 12 11 10 9 8 ???? p r e a 76543210 diva value name description 0 clk_off clka, clkb clock is turned off 1 clk_div1 clka, clkb clock is clock selected by prea, preb 2-255 ? clka, clkb clock is clock selected by prea, preb divided by diva, divb factor. value name description 0000 mck master clock 0001 mckdiv2 master clock divided by 2 0010 mckdiv4 master clock divided by 4 0011 mckdiv8 master clock divided by 8 0100 mckdiv16 master clock divided by 16 0101 mckdiv32 master clock divided by 32 0110 mckdiv64 master clock divided by 64 0111 mckdiv128 master clock divided by 128 1000 mckdiv256 master clock divided by 256 1001 mckdiv512 master clock divided by 512 1010 mckdiv1024 master clock divided by 1024
917 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38.7.2 pwm enable register name: pwm_ena address: 0x48008004 access: write-only ? chidx: channel id 0 = no effect. 1 = enable pwm output for channel x. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????c h i d 3c h i d 2c h i d 1c h i d 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 918 38.7.3 pwm disable register name: pwm_dis address: 0x48008008 access: write-only ? chidx: channel id 0 = no effect. 1 = disable pwm output for channel x. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????c h i d 3c h i d 2c h i d 1c h i d 0
919 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38.7.4 pwm status register name: pwm_sr address: 0x4800800c access: read-only ? chidx: channel id 0 = pwm output for channel x is disabled. 1 = pwm output for channel x is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????c h i d 3c h i d 2c h i d 1c h i d 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 920 38.7.5 pwm interrupt enable register name: pwm_ier address: 0x48008010 access: write-only ? chidx: channel id. 0 = no effect. 1 = enable interrupt for pwm channel x. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????c h i d 3c h i d 2c h i d 1c h i d 0
921 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38.7.6 pwm interrupt disable register name: pwm_idr address: 0x48008014 access: write-only ? chidx: channel id. 0 = no effect. 1 = disable interrupt for pwm channel x. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????c h i d 3c h i d 2c h i d 1c h i d 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 922 38.7.7 pwm interrupt mask register name: pwm_imr address: 0x48008018 access: read-only ? chidx: channel id. 0 = interrupt for pwm channel x is disabled. 1 = interrupt for pwm channel x is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????c h i d 3c h i d 2c h i d 1c h i d 0
923 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38.7.8 pwm interrupt status register name: pwm_isr address: 0x4800801c access: read-only ? chidx: channel id 0 = no new channel period has been achieved since the last read of the pwm_isr register. 1 = at least one new channel period has been achieved since the last read of the pwm_isr register. note: reading pwm_isr automa tically clears chidx flags. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????c h i d 3c h i d 2c h i d 1c h i d 0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 924 38.7.9 pwm channel mode register name: pwm_cmr[0..3] address: 0x48008200 [0], 0x48008220 [1], 0x48008240 [2], 0x48008260 [3] access: read/write ? cpre: channel pre-scaler values which are not listed in the table must be considered as ?reserved?. ? calg: channel alignment 0 = the period is left aligned. 1 = the period is center aligned. ? cpol: channel polarity 0 = the output waveform starts at a low level. 1 = the output waveform starts at a high level. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?????c p dc p o lc a l g 76543210 ???? c p r e value name description 0000 mck master clock 0001 mckdiv2 master clock divided by 2 0010 mckdiv4 master clock divided by 4 0011 mckdiv8 master clock divided by 8 0100 mckdiv16 master clock divided by 16 0101 mckdiv32 master clock divided by 32 0110 mckdiv64 master clock divided by 64 0111 mckdiv128 master clock divided by 128 1000 mckdiv256 master clock divided by 256 1001 mckdiv512 master clock divided by 512 1010 mckdiv1024 master clock divided by 1024 1011 clka clock a 1100 clkb clock b
925 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? cpd: channel update period 0 = writing to the pwm_cupdx will modify the duty cycle at the next period start event. 1 = writing to the pwm_cupdx will modify t he period at the nex t period start event.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 926 38.7.10 pwm channel duty cycle register name: pwm_cdty[0..3] address: 0x48008204 [0], 0x48008224 [1], 0x48008244 [2], 0x48008264 [3] access: read/write only the first 16 bits (internal ch annel counter size) are significant. ? cdty: channel duty cycle defines the waveform duty cycle. this value mu st be defined between 0 and cprd (pwm_cprx). 31 30 29 28 27 26 25 24 cdty 23 22 21 20 19 18 17 16 cdty 15 14 13 12 11 10 9 8 cdty 76543210 cdty
927 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38.7.11 pwm channel period register name: pwm_cprd[0..3] address: 0x48008208 [0], 0x48008228 [1], 0x48008248 [2], 0x48008268 [3] access: read/write only the first 16 bits (internal ch annel counter size) are significant. ? cprd: channel period if the waveform is left-alig ned, then the output waveform period depends on the counter source clock and can be calculated: ? by using the master clock (mck) divided by an x given prescaler value (with x being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). the resulting period formula will be: ? by using a master clock divided by one of both diva or divb divider, the formula becomes, respectively: or if the waveform is center-aligned, then the output waveform period depends on the counter source clock and can be calculated: ? by using the master clock (mck) divided by an x given prescaler value (with x being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). the resulting period formula will be: ? by using a master clock divided by one of both diva or divb divider, the form ula becomes, respectively: or 31 30 29 28 27 26 25 24 cprd 23 22 21 20 19 18 17 16 cprd 15 14 13 12 11 10 9 8 cprd 76543210 cprd xcprd () mck ------------------------------- crpd diva () mck ------------------------------------------ crpd divab () mck ---------------------------------------------- 2 xcprd () mck ---------------------------------------- 2 cprd diva () mck --------------------------------------------------- 2 cprd divb () mck ---------------------------------------------------
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 928 38.7.12 pwm channel counter register name: pwm_ccnt[0..3] address: 0x4800820c [0], 0x4800822c [1], 0x4800824c [2], 0x4800826c [3] access: read-only ? cnt: channel counter register internal counter value. this register is reset when: ? the channel is enabled (writing chidx in the pwm_ena register). ? the counter reaches cprd value defined in the pwm_ cprdx register if the wa veform is left aligned. 31 30 29 28 27 26 25 24 cnt 23 22 21 20 19 18 17 16 cnt 15 14 13 12 11 10 9 8 cnt 76543210 cnt
929 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 38.7.13 pwm channel update register name: pwm_cupd[0..3] address: 0x48008210 [0], 0x48008230 [1], 0x48008250 [2], 0x48008270 [3] access: write-only ? cupd: channel update register this register acts as a double buffer for the period or the duty cycle. this prevents an unexpected waveform when modify- ing the waveform period or duty-cycle. only the first 16 bits (internal ch annel counter size) are significant. when cpd field of pwm_cmrx register = 0, the duty-cycle (cdty of pwm_cdtyx register) is updated with the cupd value at the beginning of the next period. when cpd field of pwm_cmrx register = 1, the period (cprd of pwm_cprdx register) is updated with the cupd value at the beginning of the next period. 31 30 29 28 27 26 25 24 cupd 23 22 21 20 19 18 17 16 cupd 15 14 13 12 11 10 9 8 cupd 76543210 cupd
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 930 39. segment liquid crystal display controller (slcdc) 39.1 description the segment liquid crystal display controller (slcdc) can drive a monochrome passive liquid crystal display (lcd) with up to 6 common terminals and up to 38 segment terminals. an lcd consists of several segments (pixels or complete symbols) which can be visible or invisible. a segment has two electrodes with liquid crysta l between them. when a voltage above a threshold voltage is applied across the liquid crystal, the segment becomes visible. the voltage must alternate to avoid an electrophoresis effect in the liquid crystal, which degrades the display. hence the waveform across a segment must not have a dc component. the slcdc is programmable to support many different requirements such as: ? adjusting the driving time of the lcd pads in order to save power and increase the contro llability of the dc offset ? driving smaller lcd (down to 1 common by 1 segment) ? adjusting the slcdc frequency in order to obtain the best compromise between frequency and consumption and adapt it to the lcd driver ? assigning the segments in a user defined pattern to simplify the use of the digital functions multiplexed on these pins table 39-1. list of terms term description lcd a passive display panel with terminals leading directly to a segment segment the least viewing element (pixel) which can be on or off common(s) denotes how many segments are connected to a segment terminal duty 1/(number of common terminals on an actual lcd display) bias 1/(number of voltage levels used driving a lcd display -1) frame rate number of times the lcd segments are energized per second.
931 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.2 embedded characteristics the slcdc provides the following capabilities: ? display capacity: up to 38 segments and 6 common terminals ? support from static to 1/6 duty ? support static, 1/2, 1/3 bias ? two lcd supply sources: ? internal (on-chip lcd power supply) ? external ? lcd output voltage softwa re selectable from 2.4v to vddin in 16 steps (control embedded in the supply controller) ? flexible selection of frame frequency ? two interrupt sources: end of frame and disable ? versatile display modes ? equal source and sink capabilit y to maximize lcd life time ? segment and common pins not needed for driving th e display can be used as ordinary i/o pins ? segments layout can be fully defined by user to optimize usage of multip lexed digital functions ? latching of display data gives full freedom in register updates ? power saving modes for extremely low power consumption ? register write protection
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 932 39.3 block diagram figure 39-1. slcdc block diagram clk slcdc a p b b u s 1/3 v ddlcd 1/2 v ddlcd 2/3 v ddlcd v ddlcd v ddlcd clock m u ltiplexer pre s c a ler divide b y 1 to 8 s lcdc_dr s lcdc_frr slck/ 8 div presc slck slcdc_{l,m}memr0 slck/1024 timing generation /2 /16 com./rate uniformizer comsel display frame buffer user frame buffer comsel, lpmode, bias lcdblkfreq, dispmode endframe it generation disable buffer_on endframe bufftime, lcdblkfreq com0 com1 analog bu ffer s s lcdc_mr com4 com5 s lcdc_cr s lcdc_ier s lcdc_idr s lcdc_imr s lcdc_isr on enable, disable, swrst comsel, segsel buffer_on on-chip resistor ladder for 1/2 bias 1/2 s lcdc_ s r ena bias,bufftime, lpmode on-chip resistor ladder for 1/3 bias 2/3 1/3 an a lo g s witch array s eg0 s eg1 s eg2 s eg 3 s eg4 s eg5 s eg45 s eg46 s eg47 s eg4 8 s eg49 mux lcd seg waveform generator outp u t decoder lcd com waveform generator dispmode, segsel,lcdn bias gnd rr gnd rrr seg x (com->1) s lcdc_ smr lcdn analog/digital pad control to segn pad buffers lcdn segsel ena analog/digital pad control to comn pad buffers comsel ena slcdc_{l,m}memr1
933 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.4 i/o lines description 39.5 product dependencies 39.5.1 i/o lines the pins used for interfacing the slcd controller may be multiplexed with pi o lines. please refer to product block diagram. if i/o lines of the slcd controller are not used by the application, they can be used for other purposes by the pio controller. by default (slcdc_smr0/1 registers cleared) the assi gnment of the segment controls and commons are automatically done de pending on comsel and segsel in slcdc_mr . as example, if 10 segments are programmed in the segsel field, they are automatically assigned to seg[9 :0] whereas remaining seg pins are automatically selected to be driven by the multiplexed digital functions. anyway, the user can def ine a new layout pattern for the s egment assignment by programming the slcdc_smr0/1 registers in order to optim ize the usage of multiplexed digital function. if at least 1 bit is set in slcdc_smr0/1 registers, the corres ponding i/o line will be driven by an lc d segment whereas any cleared bit of this register will select the corres ponding multiplexed digital function. table 39-2. i/o lines description name description type seg [39:0] segments control signals output com [5:0] commons control signals output table 39-3. i/o lines instance signal i/o line peripheral slcdc com0 pa0 x1 slcdc com1 pa1 x1 slcdc com2 pa2 x1 slcdc com3 pa3 x1 slcdc com4/ad1 pa4 x1 slcdc com5/ad2 pa5 x1 slcdc seg0 pa6 x1 slcdc seg1 pa7 x1 slcdc seg2 pa8 x1 slcdc seg3 pa9 x1 slcdc seg4 pa10 x1 slcdc seg5 pa11 x1 slcdc seg6/ad0 pa12 x1 slcdc seg7 pa13 x1 slcdc seg8 pa14 x1 slcdc seg9 pa15 x1 slcdc seg10 pa16 x1 slcdc seg11 pa17 x1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 934 slcdc seg12 pa18 x1 slcdc seg13 pa19 x1 slcdc seg14 pa20 x1 slcdc seg15 pa21 x1 slcdc seg16 pa22 x1 slcdc seg17 pa23 x1 slcdc seg18 pa24 x1 slcdc seg19 pa25 x1 slcdc seg20 pa26 x1 slcdc seg21 pa27 x1 slcdc seg22 pa28 x1 slcdc seg23 pa29 x1 slcdc seg24 pb6 x1 slcdc seg25 pb7 x1 slcdc seg26 pb8 x1 slcdc seg27 pb9 x1 slcdc seg28 pb10 x1 slcdc seg29 pb11 x1 slcdc seg30 pb12 x1 slcdc seg31/ad3 pb13 x1 slcdc seg32 pb14 x1 slcdc seg33 pb15 x1 slcdc seg34 pb16 x1 slcdc seg35 pb17 x1 slcdc seg36 pb18 x1 slcdc seg37 pb19 x1 slcdc seg38 pb20 x1 slcdc seg39 pb21 x1 slcdc seg40 pb22 x1 slcdc seg41/ad4 pb23 x1 slcdc seg42 pb24 x1 slcdc seg43 pb25 x1 slcdc seg44 pb26 x1 slcdc seg45 pb27 x1 slcdc seg46 pb28 x1 slcdc seg47 pb29 x1 slcdc seg48 pb30 x1 slcdc seg49/ad5 pb31 x1 table 39-3. i/o lines
935 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.5.2 power management the slcd controller is clocked by the slow clock (slck). all the timings are based upon a typical value of 32 khz for slck. the lcd segment/common pad buffers are supplied by the vddlcd domain. 39.5.3 interrupt sources the slcd controller interr upt line is connected to one of the internal sources of the interrupt controller. using the slcd controller interr upt requires prior programming of the interrupt controller. table 39-4. peripheral ids instance id slcdc 32
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 936 39.6 functional description the use of the slcdc comprises three pha ses of functionality: initialization sequence, display phase, and disable sequence. ? initialization sequence: 1. select the lcd supply source in the shutdown controller ? internal: the on-chip lcd power supply is selected, ? external: the external supply source has to be between 2.5 to 3.6v 2. select the clock division (slcdc_frr) to use a proper frame rate 3. enter the number of common and segments terminals (slcdc_mr) 4. select the bias in compliance with th e lcd manufacturer datasheet (slcdc_mr) 5. enter buffer driving time (slcdc_mr) 6. define the segments remapping pattern if required (slcdc_smr0/1) ? during the display phase: 1. data may be written at any time in the slcdc memory, they are automatically latched and displayed at the next lcd frame 2. it is possible to: ? adjust contrast ? adjust the frame frequency ? adjust buffer driving time ? reduce the slcdc consumption by enteri ng in low-power waveform at any time ? use the large set of display features such as blinking, inverted blink, etc. ? disable sequence: see section 39.6.7 ? disabling the slcdc?
937 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.6.1 clock generation 39.6.1.1 block diagram figure 39-2. clock generation block diagram clock clk slcdc clk slcdc slcdc_frr div presc lcd seg waveform generator timing generation comsel lcd com waveform generator buffer_on endframe slcdc_mr comsel segsel com + seg waveform generator bufftime buffer driving time management lpmode slcdc_dr lcdblkfreq blinking generator blink period mux prescaler divider (1 to 8) slck /2 /16 com./rate uniformizer slck/8 slck/1024
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 938 39.6.2 waveform generation 39.6.2.1 static duty and bias this kind of display is driven with the waveform shown in figure 39-3 . seg0 - com0 is the voltage across a seg- ment that is on, and seg1 - com0 is the voltage across a segment that is off. figure 39-3. driving an lcd with one common terminal 39.6.2.2 1/2 duty and 1/2 bias for an lcd with two common terminals (1/2 duty) a more complex waveform must be used to control segments individually. although 1/3 bias can be selected, 1/2 bi as is most common for these displays. in the waveform shown in figure 39-4 , seg0 - com0 is the voltage across a segment that is on, and seg0 - com1 is the voltage across a segment that is off. figure 39-4. driving an lcd with two common terminals v ddlcd gnd v ddlcd gnd v ddlcd gnd -v ddlcd frame frame v ddlcd gnd v ddlcd gnd gnd seg1 com0 seg1 - com0 frame frame seg0 com0 seg0 - com0 v ddlcd gnd v ddlcd 1 / 2 v ddlcd gnd v ddlcd 1 / 2 v ddlcd gnd -1 / 2 v ddlcd -v ddlcd seg0 com0 seg0 - com0 v ddlcd gnd v ddlcd 1 / 2 v ddlcd gnd v ddlcd 1 / 2 v ddlcd gnd -1 / 2 v ddlcd -v ddlcd seg0 com1 seg0 - com1 frame frame frame frame
939 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.6.2.3 1/3 duty and 1/3 bias 1/3 bias is usually recommended for an lcd with three common terminals (1/3 duty). in the waveform shown in figure 39-5 , seg0 - com0 is the voltage across a segment that is on and seg0 - com1 is the voltage across a segment that is off. figure 39-5. driving an lcd with three common terminals frame frame frame frame v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com0 seg0 - com0 v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com1 seg0 - com1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 940 39.6.2.4 1/4 duty and 1/3 bias 1/3 bias is optimal for lcd displays with four common terminals (1/4 duty). in the waveform shown in figure 39-6 , seg0 - com0 is the voltage across a segment that is on and seg0 - com1 is the voltage across a segment that is off. figure 39-6. driving an lcd with four common terminals frame frame frame frame v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com0 seg0 - com0 v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com1 seg0 - com1
941 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.6.2.5 low power waveform to reduce toggle activity and hence power consumption, a low power waveform can be selected by writing lpmode to one. the default and low power waveform is shown in figure 39-7 for 1/3 duty and 1/3 bias. for other selections of duty and bias, the effect is similar. figure 39-7. default and low power waveform note: refer to the lcd specification to veri fy that low power wave forms are supported. 39.6.2.6 frame rate the frame rate register (slcdc_frr) enables the generation of the frequency used by the slcdc. it is done by a prescaler (division by 8, 16, 32, 64, 128, 256, 512 and 1024) followed by a finer divider (division by 1, 2, 3, 4, 5, 6, 7 or 8). to calculate the needed frame frequency, the equation below must be used: where: f slck = slow clock frequency f frame = frame frequency presc = prescaler value (8, 16, 32, 64, 128, 256, 512 or 1024) div = divider value (1, 2, 3, 4, 5, 6, 7, or 8) ncom = depends of number of commons and is defined in table 39-5 . ncom is automatically provided by the slcdc. as example, if comsel is programmed to 0 (1 common terminal on display device), the slcdc introduces a divider by 16 so that ncom = 16. if comsel is progr ammed to 3 (3 common terminals on display device), the slcdc introduces a divider by 5 so that the ncom remains close to 16 (frame rate is uniformized whatever the number of driven commons). frame frame frame frame v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com0 seg0 - com0 v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com0 seg0 - com0 f frame fsclk presc div ncom ?? () ------------------------------------------------------------- - =
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 942 39.6.2.7 buffer driving time intermediate voltage levels are generated from buffer drivers. the buffers are active the amount of time specified by buftime[3:0] in slcdc_mr, then buffers are bypassed. shortening the drive time will reduce po wer consumption, but displays with high internal resistance or capacitance may need longer drive time to achieve sufficient contrast. example for bias = 1/3. figure 39-8. buffer driving 39.6.3 number of commons, segments and bias it is important to note that the selection of the number of commons, segments and the bias can be programmed when the slcdc is disabled. table 39-5. ncom number of commons nco m uniformizer divider 11616 2168 3155 4164 5153 6183 slcdc_mr bufftime v ddlcd r r r 2/3 v ddlcd 1/3 v ddlcd
943 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.6.4 slcdc memory figure 39-9. memory management when a bit in the displa y memory (slcdc_lmemrx and slcdc_mmemrx registers) is written to one, the corresponding segment is energized (o n), and non-energized when a bit in the display memory is written to zero. at the beginning of each common, the display buffer is updated. the value of the previous common is latched in the display memory (its value is transferred from the user buffer to the fr ame buffer). the advantages of this solution are: ? ability to access the user bu ffer at any time in the frame, in any display mode and even in low power waveform ? ability to change only one pixe l without reloading the picture 39.6.5 display features in order to improve the flexib ility of slcdc the following set of display mode s are embedded: ? force mode off: all pixels are turned off and the memory content is kept. ? force mode on: all pixels are turned on and the memory content is kept. ? inverted mode: all pixels are set in the inverted state as defined in slcdc memory and t he memory content is kept. ? two blinking modes: ? standard blinking mode: all pixels are alternately turned off to the predefined state in slcdc memory at lcdblkfreq frequency. ? inverted blinking mode: all pixels are alternately turned off to the predefined opposite state in slcdc memory at lcdblkfreq frequency. ? buffer swap mode: all pixels are alternatively assigned to the state defined in the user buffer then to the state defined in the display buffer. 39.6.6 buffer swap mode this mode allows to assign all pixels to two states alternatively without reloading the user buffer at each change. the means to alternatively display two states is as follows: load data from the user buff to the disp buff display data previously loaded from the user buffer to the disp buffer load data from the user buffer to the disp buffer display data previously loaded from the user buffer to the disp buffer load data from the user buffer to the disp buffer display data previously loaded from the user buffer to the disp buffer com0 time slot com1 time slot com2 time slot com0 com1 com2
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 944 1. initially, the slcdc must be in normal mode or in a standard blinking mode. 2. data corresponding to the first pixel state is writt en in the user buffer (thr ough the slcdc_me m registers). 3. wait two endframe events (to be sure that the user buffer is entirely transferred in the display buffer). 4. slcdc_dr must be programmed with dispmode = 6 (user buffer only load mode). this mode blocks the automatic transfer from the user buffer to the display buffer. 5. wait endframe event. (the display mode is inte rnally updated at the beginning of each frame.) 6. data corresponding to the second pixel state is written in the user buffer (through the slcdc_mem registers). so, now the first pixel state is in the display buffer and the second pixel state is in the user buffer. 7. slcdc_dr must be programmed with dispmode = 7 (buffer swap mode) and lcdblkfreq must be programmed with the wanted blinking frequency (if not previously done). now, each state is alternatively displayed at lcdblkfreq frequency. except for the phase dealing with the storage of the tw o display states, the management of the buffer swap mode is the same as the standard blinking mode. 39.6.7 disabling the slcdc there are two ways to disable the slcdc: ? by using the slcdc_cr[lcddis] bit (recommended me thod). in this case, slcdc configuration and memory content are maintained. ? by using the swrst (software reset) bit that acts like a hardware reset for slcdc only. both methods are described in the following sections. 39.6.7.1 disable bit the lcddis bit in the slcdc_cr can be set at any ti me. when the lcd disable command is activated during a frame, the slcdc is not immediately stopped (see figure 39-10 ). the next frame will be generated in ?all ground? mode (whereby all commons and segments will be tied to ground). at the end of this ?all ground? frame, the disa ble interrupt is asserted if the bit dis is set in the slcdc_imr. the slcdc is now disabled.
945 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 39-10. disabling sequence 39.6.7.2 software reset when the slcdc software reset command is activated during a frame it is imme diately processed and all commons and segments are tied to ground. note that in the case of a software reset, the disable interrupt is not asserted. figure 39-11. software reset end of frame interrupt common disable example for three commons ena bit slcdc interrupt v ddlcd -v ddlcd gnd 1/3 -1/3 disable command commons/segments tied to ground command processing begins disable command is activated slcdc disabled end of frame interrupt common v ddlcd -v ddlcd gnd 1/3 -1/3 sw reset example for three commons sw reset command the common is immediatly tied to ground the sw reset command is activated
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 946 39.6.8 flowchart figure 39-12. slcdc flow chart enter/exit from low-power wave form? change the frame rate ? no no no lpmode in slcdc_mr presc + div in slcdc_frr buftime in slcdc_mr disable the slcdc ? sw reset ? swrst in slcdc_cr lcddis in slcdc_cr disable interrupt? no dis in slcdc_isr ena bit = 0? no ena in slcdc_sr no blink? change/update the display mode (dispmode in slcdc_dr) no - normal mode - force off - force on - inverted mode change/update the display mode (dispmode in slcdc_dr) - blinking mode - inverted blinking mode change/update the blinking frequency (lcdblkfreq in slcdc_dr) change the power comsumption ? no ena = 1? ena in slcdc_sr no update the displayed data? write the new data in the slcdc_mem no no update/change the display mode? initialization supply source (internal or external) number of com (comsel in slcdc_mr) number of seg (segsel in slcdc_mr) frame rate ((presc + div) in slcdc_frr) buff on time (buftime in slcdc_mr) bias (bias in slcdc_mr) enables the slcdc lcden in slcdc_mr end start
947 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.6.9 user buffer organization the pixels to be displayed are written into slcdc_lm emrx and slcdc_mmemrx registers. there are up to two 32-bit registers for each common terminal. table 39-6 provides the address mapping of all commons/segments to be displayed. if the segment map registers (slcdc_smr0/1) are cleared and the number of segments to handle (segsel field in slcdc_mr) is lower or equal to 32, the registers slcdc_mmemrx ar e not required to be programmed and can be left cleared (default value). in case segments are re mapped, the slcdc_mmemrx registers ar e not required to be programmed if slcdc_smr1 register is cleared (i.e., no segment remapped on seg32 to seg39 i/o pins). in this case slcdc_mmemrx registers must be cleared. in the same way if all segments are remapped on the upper part of the seg terminals (seg32 to seg39) there is no need to program slcdc_lmemrx registers (they must be cleared). when segment remap is used (slcdc _smr0/1 registers differ from 0), the unmapped segments must be kept cleared to limit inter nal signal switching. 39.6.10 segments mapping function by default the segments pins (seg0:39 ) are automatically assigned according to the segsel configuration in the slcdc_mr. the unused seg i/o pins are forced to be driven by a digital peripheral or can be used as i/o through the pio controller. the automatic assignment is performed if the segment ma pping function is not used (slcdc_smr0/1 registers are cleared). the following table provides such assignments. table 39-6. commons/segments address mapping register common terminal seg0 -- seg31 seg32 -- seg39 memory address slcdc_mmemr5 slcdc_lmemr5 com5 com5 x -- x x-- x0x22c 0x228 slcdc_mmemr4 slcdc_lmemr4 com4 com4 x -- x x-- x 0x224 0x220 slcdc_mmemr3 slcdc_lmemr3 com3 com3 x -- x x-- x0x21c 0x218 slcdc_mmemr2 slcdc_lmemr2 com2 com2 x -- x x-- x 0x214 0x210 slcdc_mmemr1 slcdc_lmemr1 com1 com1 x -- x x-- x0x20c 0x208 slcdc_mmemr0 slcdc_lmemr0 com0 com0 x -- x x-- x 0x204 0x200 table 39-7. segment pin assignments segsel i/o port in use as segment driver i/o port pin if slcdc_smr0/1 = 0 0 seg0 seg1:39 1 seg0:1 seg2:39
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 948 programming is straightfo rward in this mode but it prev ents flexibility of use of the digital periphera l multiplexed on seg0:39 especially when the number of segments to drive is close to the maximum (38). for example, if the segsel is set to 37, only the digital peripheral associated to seg39 can be used and none of the other digital peripherals mult iplexed on seg0:37 i/o can be used. to offer a flexible selection of digital peripherals mult iplexed on seg0:39 the user can manually configure the seg i/o pins to be driven by the slcdc. this is done by programming the slcdc_smr0/1 registers. as soon as their values differ from 0 the segment remapping mode is used. when configuring a logic 1 at index n (n = 0..39) in slcdc_smr0 or slcdc_smr0, the slcdc forces the segn i/o pin to be driven by a segment wa veform. in this mode t he segsel field configuration value in slcdc_mr is ignored. in remapping mode the software dispatches the pixels into slcdc_lmemrx or slcdc_mmemrx according to what is programmed in slcdc_smr0 or slcdc_smr0. ... ... ... 37 seg0:37 seg39 39 seg0:39 none table 39-7. segment pin assignments segsel i/o port in use as segment driver i/o port pin if slcdc_smr0/1 = 0
949 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 39-13. segments remapping example com0 com1 seg0 seg1 seg2 seg3 lcd display panel microcontroller com0 com1 com5 seg0 seg1 seg2 seg3 seg4 seg28 seg29 seg30 dig0 dig1 dig5 dig6 dig7 dig8 dig9 dig10 dig11 dig12 dig13 comsel=1 segsel=3 slcdc_smr0=0 slcdc_smr1=0 slcdc_lmemr0=0x5 slcdc_lmemr1=0xa com0 com1 seg0 seg1 seg2 seg3 lcd display panel microcontroller com0 com1 com5 seg0 seg1 seg2 seg3 seg4 seg28 seg29 seg30 dig0 dig1 dig5 dig6 dig7 dig8 dig9 dig10 dig11 dig12 dig13 comsel=1 segsel=3 slcdc_smr0=0x8000_0002 slcdc_smr1=0x0000_0003 slcdc_lmemr0=0x2 slcdc_mmemr0=0x1 slcdc_lmemr1=0x8000_0000 slcdc_mmemr1=0x0000_0002 default segment pins assigments user remapped segment pins assigments user config. default config. unusable digital functions dig10 dig11 dig12 dig13 lcd panel config. direct image buffer pre-processed image buffer dig6 dig8 dig9 dig10
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 950 39.6.11 register write protection to prevent any single software error from corrupting slcd c behavior, certain registers in the address space can be write-protected by setting the wpen bit in the slcdc write protection mode register (slcdc_wpmr). if a write access to a write-protected regi ster is detected, the wpvs bit in the slcdc write protection status register (slcdc_wpsr) is set and the fiel d wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically clea red after reading the slcdc_wpsr. the following registers can be write-protected: ? slcdc mode register ? slcdc frame rate register ? slcdc display register ? slcdc segment map register 0 ? slcdc segment map register 1 39.7 waveform specifications 39.7.1 dc characteristics refer to the dc characteristics section of the product datasheet. 39.7.2 lcd contrast the peak value (v ddlcd ) on the output waveform determines the lcd contrast. v ddlcd is controlled by software in 16 steps from 2.4v to vddin. this is a function of the supply controller.
951 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8 segment lcd controlle r (slcdc) user interface table 39-8. register mapping offset register name access reset 0x0 slcdc control register slcdc_cr write-only ? 0x4 slcdc mode register slcdc_mr read/write 0x0 0x8 slcdc frame rate register slcdc_frr read/write 0x0 0xc slcdc display register slcdc_dr read/write 0x0 0x10 slcdc status register slcdc_sr read-only 0x0 0x20 slcdc interrupt enable register slcdc_ier write-only ? 0x24 slcdc interrupt disable register slcdc_idr write-only ? 0x28 slcdc interrupt mask register slcdc_imr read-only ? 0x2c slcdc interrupt status register slcdc_isr read-only 0x0 0x30 slcdc segment map register 0 slcdc_smr0 read/write 0x0 0x34 slcdc segment map register 1 slcdc_smr1 read/write 0x0 0x38?0xe4 reserved ? ? ? 0xe4 slcdc write protection mode register slcdc_wpmr read/write 0x0 0xe8 slcdc write protection status register slcdc_wpsr read-only 0x0 0xec?0xf8 reserved ? ? ? 0xfc reserved ? ? ? 0x200 + com*0x8 + 0x0 slcdc lsb memory register slcdc_lmemr read/write 0x0 0x200 + com*0x8 + 0x4 slcdc msb memory register slcdc_mmemr read/write 0x0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 952 39.8.1 slcdc control register name: slcdc_cr address: 0x4003c000 access: write-only ? lcden: enable the lcdc 0: no effect. 1: the slcdc is enabled. ? lcddis: disable lcdc 0: no effect. 1: the slcdc is disabled. note: lcddis is processed at th e beginning of the next frame. ? swrst: software reset 0: no effect. 1: equivalent to a power-up reset. when this command is performed, the slcdc immediately ties all segments end com- mons lines to values corresponding to a ?ground voltage?. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????s w r s t?l cddis lcden
953 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8.2 slcdc mode register name: slcdc_mr address: 0x4003c004 access: read/write this register can only be written if the wpen bit is cleared in the slcdc write protection mode register . ? comsel: selection of the number of commons (for safety reasons, can be configured when slcdc is disabled) ? segsel: selection of the number of segments (for safety reasons, can be configured when slcdc is disabled) segsel must be programmed with the number of segments of the display panel minus 1. if segment remapping function is not used (i.e., slcdc_smrx equal 0) the segn [n = 0..39] i/o pins where n is greater than segsel are forced to be driven by digital function. when segments remapping function is used, segn pins are driven by slcdc only if corresponding pixeln co nfiguration bit is set in slcdc_smr1/0 registers. 31 30 29 28 27 26 25 24 ???????l p m o d e 23 22 21 20 19 18 17 16 ? ? bias buftime 15 14 13 12 11 10 9 8 ? ? segsel 76543210 ????? c o m s e l value name description 0x0 com_0 com0 is driven by slcdc, co m1:5 are driven by digital function 0x1 com_0to1 com0:1 are driven by slcdc, co m2:5 are driven by digital function 0x2 com_0to2 com0:2 are driven by slcdc, co m3:5 are driven by digital function 0x3 com_0to3 com0:3 are driven by slcdc, co m4:5 are driven by digital function 0x4 com_0to4 com0:4 are driven by slcdc, com5 is driven by digital function 0x5 com_0to5 com0:5 are driven by slcdc, no com pin driven by digital function
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 954 ? buftime: buffer on-time (processed at beginning of next frame) ? bias: lcd display configuration (for safety reasons, can be configured when slcdc is disabled) ? lpmode: low power mode (processed at beginning of next frame) 0: normal mode. 1: low power waveform is enabled. value name description 0x0 off nominal drive time is 0% of slck period 0x1 x2_slck_period nominal drive time is 2 periods of slck clock 0x2 x4_slck_period nominal drive time is 4 periods of slck clock 0x3 x8_slck_period nominal drive time is 8 periods of slck clock 0x4 x16_slck_period nominal drive time is 16 periods of slck clock 0x5 x32_slck_period nominal drive time is 32 periods of slck clock 0x6 x64_slck_period nominal drive time is 64 periods of slck clock 0x7 x128_slck_period nominal drive time is 128 periods of slck clock 0x8 percent_50 nominal drive time is 50% of slck period 0x9 percent_100 nominal drive time is 100% of slck period value name description 0x0 static static 0x1 bias_1_2 bias 1/2 0x2 bias_1_3 bias 1/3
955 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8.3 slcdc frame rate register name: slcdc_frr address: 0x4003c008 access: read/write this register can only be written if the wpen bit is cleared in the slcdc write protection mode register . ? presc: clock prescaler (processed at beginning of next frame) ? div: clock division (processed at beginning of next frame) 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????? d i v 76543210 ????? p r e s c value name description 0x0 slck_div8 slow clock is divided by 8 0x1 slck_div16 slow clock is divided by 16 0x2 slck_div32 slow clock is divided by 32 0x3 slck_div64 slow clock is divided by 64 0x4 slck_div128 slow clock is divided by 128 0x5 slck_div256 slow clock is divided by 256 0x6 slck_div512 slow clock is divided by 512 0x7 slck_div1024 slow clock is divided by 1024 value name description 0x0 presc_clk_div1 clock output from prescaler is divided by 1 0x1 presc_clk_div2 clock output from prescaler is divided by 2 0x2 presc_clk_div3 clock output from prescaler is divided by 3 0x3 presc_clk_div4 clock output from prescaler is divided by 4 0x4 presc_clk_div5 clock output from prescaler is divided by 5 0x5 presc_clk_div6 clock output from prescaler is divided by 6 0x6 presc_clk_div7 clock output from prescaler is divided by 7 0x7 presc_clk_div8 clock output from prescaler is divided by 8
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 956 39.8.4 slcdc display register name: slcdc_dr address: 0x4003c00c access: read/write this register can only be written if the wpen bit is cleared in the slcdc write protection mode register . ? dispmode: displa y mode register (processed at beginning of next frame) ? lcdblkfreq: lcd blinki ng frequency selection (processed at beginning of next frame) blinking frequency = frame frequency/lcdblkfreq[7:0]. note: 0 written in lcdblkfreq stops blinking. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 lcdblkfreq 76543210 ????? dispmode value name description 0x0 normal normal mode?latched data are displayed. 0x1 force_off force off mode ? all pixels are invisible. (the slcdc memory is unchanged.) 0x2 force_on force on mode?all pixels are visible. (the slcdc memory is unchanged.) 0x3 blinking blinking mode?all pixels are alternately turned off to the predefined state in slcdc memory at lcdblkfreq frequency. (the slcdc memory is unchanged.) 0x4 inverted inverted mode?all pixels are set in the inverted state as defined in slcdc memory. (the slcdc memory is unchanged.) 0x5 inverted_blink inverted blinking mode?all pixels are alternatel y turned off to the predefined opposite state in slcdc memory at lcdblkfreq frequency. (the slcdc memory is unchanged.) 0x6 user_buffer_load user buffer only load mode?bloc ks the automatic transfer fr om user buffer to display buffer. 0x7 buffers_swap buffer swap mode?all pixels are alternatively assigned to the state defined in the user buffer, then to the state defined in the dis play buffer at lcdblkfreq frequency.
957 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8.5 slcdc status register name: slcdc_sr address: 0x4003c010 access: read-only ? ena: enable status (automatically set/reset) 0: the slcdc is disabled. 1: the slcdc is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????e n a
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 958 39.8.6 slcdc interrupt enable register name: slcdc_ier address: 0x4003c020 access: write-only ? endframe: end of frame interrupt enable 0: no effect. 1: enables the corresponding interrupt. ? dis: slcdc disable comp letion interrupt enable 0: no effect. 1: enables the corresponding interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????d i s?e n d f r a m e
959 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8.7 slcdc interrupt disable register name: slcdc_idr address: 0x4003c024 access: write-only ? endframe: end of frame interrupt disable 0: no effect. 1: disables the corresponding interrupt. ? dis: slcdc disable comple tion interrupt disable 0: no effect. 1: disables the corresponding interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????d i s?e n d f r a m e
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 960 39.8.8 slcdc interrupt mask register name: slcdc_imr address: 0x4003c028 access : read-only ? endframe: end of frame interrupt mask 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. ? dis: slcdc disable comp letion interrupt mask 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????d i s?e n d f r a m e
961 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8.9 slcdc interrupt status register name: slcdc_isr address: 0x4003c02c access: read-only ? endframe: end of frame interrupt status 0: no end of frame occurred since the last read. 1: end of frame occurred since the last read. ? dis: slcdc disable comp letion interrupt status 0: the slcdc is enabled. 1: the slcdc is disabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?????d i s?e n d f r a m e
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 962 39.8.10 slcdc segment map register 0 name: slcdc_smr0 address: 0x4003c030 access: read/write this register can only be written if the wpen bit is cleared in the slcdc write protection mode register . ? lcdx: lcd segment mapped on segx i/o pin (for safety reasons, can be configured when slcdc is disabled) 0: the correspondin g i/o pin will be driven either by slcdc or digital function according to segsel field configuration in the slcdc_mr. 1: an lcd segment will be driv en on corresponding i/o pin. 31 30 29 28 27 26 25 24 lcd31 lcd30 lcd29 lcd28 lcd27 lcd26 lcd25 lcd24 23 22 21 20 19 18 17 16 lcd23 lcd22 lcd21 lcd20 lcd19 lcd18 lcd17 lcd16 15 14 13 12 11 10 9 8 lcd15 lcd14 lcd13 lcd12 lcd11 lcd10 lcd9 lcd8 76543210 lcd7 lcd6 lcd5 lcd4 lcd3 lcd2 lcd1 lcd0
963 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8.11 slcdc segment map register 1 name: slcdc_smr1 address: 0x4003c034 access: read/write this register can only be written if the wpen bit is cleared in the slcdc write protection mode register . ? lcdx: lcd segment mapped on segx i/o pin (for safety reasons, can be configured when slcdc is disabled) 0: the correspondin g i/o pin will be driven either by slcdc or digital function according to segsel field configuration in the slcdc_mr. 1: an lcd segment will be driv en on corresponding i/o pin. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ??????l c d 4 9l c d 4 8 15 14 13 12 11 10 9 8 lcd47 lcd46 lcd45 lcd44 lcd43 lcd42 lcd41 lcd40 76543210 lcd39 lcd38 lcd37 lcd36 lcd35 lcd34 lcd33 lcd32
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 964 39.8.12 slcdc write protection mode register name: slcdc_wpmr address: 0x4003c0e4 access: read/write ? wpen: write protection enable 0: disables write pr otection if wpkey corresponds to 0x4c4344 (?lcd? in ascii). 1: enables write protection if wpkey corresponds to 0x4c4344 (?lcd? in ascii). see section 39.6.11 ?register write protection? for the list of registers which can be protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x4c4344 passwd writing any other value in this field abor ts the write operation of the wpen bit. always reads as 0.
965 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8.13 slcdc write protection status register name: slcdc_wpsr address: 0x4003c0e8 access: read-only ? wpvs: write protection violation status 0: no write protection violation has occu rred since the last read of the slcdc_wpsr. 1: a write protection violation has occurr ed since the last read of the slcdc_wpsr . if this violation is an unauthorized attempt to write a prot ected register, the asso ciated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at whic h a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 966 39.8.14 slcdc lsb memory register name: slcdc_lmemrx [x = 0..5] address: 0x4003c200 [0], 0x4003c208 [1], 0x4003c210 [2], 0x4003c218 [3], 0x4003c220 [4], 0x4003c228 [5] access: read/write ? lpixel: lsb pixels pattern associated to comx terminal 0: the pixel associated to comx terminal is no t visible (if non-inverted display mode is used). 1: the pixel associated to comx terminal is visible (if non-inverted display mode is used). note: lpixel[n] (n = 0..31) drives segn terminal. 31 30 29 28 27 26 25 24 lpixel 23 22 21 20 19 18 17 16 lpixel 15 14 13 12 11 10 9 8 lpixel 76543210 lpixel
967 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 39.8.15 slcdc msb memory register name: slcdc_mmemrx [x = 0..5] address: 0x4003c204 [0], 0x4003c20c [1], 0x4003c214 [2], 0x 4003c21c [3], 0x4003c224 [4], 0x4003c22c [5] access: read/write ? mpixel: msb pixels pattern associated to comx terminal 0: the pixel associated to comx terminal is no t visible (if non-inverted display mode is used). 1: the pixel associated to comx terminal is visible (if non-inverted display mode is used). note: mpixel[n] (n = 32..39) drives segn terminal. 31 30 29 28 27 26 25 24 mpixel 23 22 21 20 19 18 17 16 mpixel 15 14 13 12 11 10 9 8 mpixel 76543210 mpixel
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 968 40. analog-to-digital converter (adc) 40.1 description the adc is based on a 10-bit analog-to-digital converter (adc) managed by an adc controller. it also integrates a 6-to-1 analog multiplexer, making possi ble the analog-to-digital conversions of 6 analog lines. the conversions extend from 0v to the voltage carried on pin advref or the voltage provided by the internal reference voltage which can be programmed in the analog control register (adc_acr). selection of the reference voltage source is defined by the onref and forceref bits in the analog control register (adc_acr). the adc supports the 8-bit or 10-bit resolution mode. the 8-bit resolution mode prevents using the 16-bit peripheral dma transfer into memory when only 8-bit resoluti on is required by the application. note that using this low resolution mode does not increase the conversion rate. conversion results are reported in a common register for all channels, as well as in a channel-dedicated register. the 11-bit and 12-bit resolution modes are obtained by averaging multiple samples to decrease quantization noise. for 11-bit mode, four samples are used, giving an effective sample rate of 1/4 of the actual sample frequency. for 12-bit mode, 16 samples are used, giving an effective sample rate of 1/16th of the actual sample frequency. this allows conversion s peed to be traded for better accuracy. the last channel is internally connected to a temperat ure sensor. the processing of this channel can be fully configured for efficient downstream processing due to the slow frequency variation of the value carried on such a sensor. the seventh channel is reserved for measurement of vddbu voltage. the software trigger or internal triggers from timer counter output(s) are configurable. the main comparison circuitry allows automatic detection of values below a threshold, higher than a threshold, in a given range or outside the range. thresh olds and ranges are fully configurable. the adc also integrates a sleep mode and a conversion sequencer, and connects wi th a pdc channel. these features reduce both power consum ption and processor intervention. finally, the user can configure adc timings, such as startup time and tracking time.
969 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.2 embedded characteristics ? 10-bit resolution with en hanced mode up to 12 bits ? 500 k hz conversion rate ? digital averaging function provides enhanced resolution mode up to 12 bits ? on-chip temperature sensor management ? wide range of power supply operation ? selectable external voltage reference or programmable internal reference ? integrated multiplexer offering up to 6 independent analog inputs ? individual enable and disable of each channel ? hardware or software trigger ? external trigger pin ? timer counter outputs (corresponding tioa trigger) ? pdc support ? possibility of adc timings configuration ? two sleep modes and conversion sequencer ? automatic wakeup on trigger and back to sleep mode after conversions of all enabled channels ? possibility of custom ized channel sequence ? standby mode for fast wakeup time response ? power down capability ? automatic window comparison of converted values ? register write protection
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 970 40.3 block diagram figure 40-1. analog-to-digital converter block diagram 40.4 signal description note: 1. ad7 is not an actual pin; it is in ternally connected to a temperature sensor. 2. ad6 is not an actual pin; it is internally connected to vddbu. 3. ad4 and ad5 channels are not wired to i/o lines and thus cannot be measured. in the channel enable register (adc_cher), these channels must be kept off by en suring that the bits 4 and 5 are always cleared. adc interrupt advref gnd trigger selection control logic successive approximation register analog-to-digital converter timer counter channels user interface interrupt controller peripheral bridge apb pdc system bus analog inputs multiplexed with i/o lines pio ad- ad- ad- adc controller adc cell chx internal voltage reference onref temp. sensor 1hz rtc forceref vddin vddbu 6 7 peripheral clock pmc bus clock adc clock table 40-1. adc pin description pin name description advref external reference voltage ad0 - ad 7 (1)(2)(3) analog input channels
971 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.5 product dependencies 40.5.1 power management the adc controller is not continuously clocked. the programmer must first enable the adc controller peripheral clock in the power management controller (pmc) before using the adc controller. ho wever, if the application does not require adc operations, the adc controller cl ock can be stopped when not needed and restarted when necessary. configuring the adc controller does no t require the adc controller clock to be enabled. 40.5.2 interrupt sources the adc interrupt line is connected on one of the intern al sources of the interrupt controller. using the adc interrupt requires th e interrupt controller to be programmed first. 40.5.3 analog inputs the analog input pins can be multiplexed with pio lines. in this case, the assignment of the adc input is automatically done as soon as the corresponding channel is enabled by writing the channel enable register (adc_cher). by default, after reset, the pio line is configured as a digital input with its pull-up enabled, and the adc input is connected to the gnd. 40.5.4 temperature sensor the temperature sensor is internally connected to channel index 7 of the adc. the temperature sensor provides an output voltage v t that is proportional to the absolute temperature (ptat). to activate the temperature sensor, the tempon bit in the temperature sensor mode register (adc_tempmr) must be set. after setting the bit, the startup time of the temperature sensor must be achieved prior to initiating any measurement. 40.5.5 i/o lines 40.5.6 timer triggers timer counters may or may not be used as hardware tri ggers depending on user requirements. thus, some or all of the timer counters may be unconnected. 40.5.7 conversion performances for performance and electrical charac teristics of the adc, see the section ?electrical characteristics?. table 40-2. peripheral ids instance id adc 29 table 40-3. i/o lines instance signal i/o line peripheral adc com4/ad1 pa4 x1 adc com5/ad2 pa5 x1 adc seg6/ad0 pa12 x1 adc seg31/ad3 pb13 x1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 972 40.6 functional description 40.6.1 analog-to-digital conversion the adc uses the adc clock to perform conversions. converting a single analog value to a 10-bit digital data requires tracking clock cycles as defined in the field tracktim of the ?adc mode register? (adc_mr). the adc clock frequency is selected in the prescal field of adc_mr. the adc clock frequency is between f peripheral clock /2 if prescal is 0, and f peripheral clock /512 if prescal is set to 255 (0xff). prescal must be programmed in order to provide an a dc clock frequency according to the parameters given in the section ?electrica l characteristics?. figure 40-2. sequence of adc conversions 40.6.2 conversion reference the conversion is performed on a full range between 0v and the reference voltage. the reference voltage is defined by the external pin advref, or programmed usi ng the internal reference voltage configured in adc_acr. analog inputs between these voltages convert to values based on a linear conversion. 40.6.3 conversion resolution the adc supports 8-bit or 10-bit resolutions. the 8-bit selection is performed by setting the lowres bit in adc_mr. by default, after a reset, the re solution is the highest and the data field in the data registers is fully used. by setting the lowres bit, t he adc switches to the lowest reso lution and the conversion results can be read in the lowest significant bits of the data registers. the two highest bits of the da ta field in the corresponding channel data register (adc_ cdr) and of the ldata field in the last converted data register (adc_lcdr) read 0. adcclock lcdr adc_on adc_sel drdy adc_start ch0 ch1 ch0 ch2 ch1 sta rt up time (and tr a cking of ch0) conver sion of ch0 conver sion of ch1 tr a cking of ch1 tr a cking of ch2 adc_eoc trigger event (hard or soft) analog cell ios
973 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.6.4 conversion results when a conversion is completed, the resulting 10-bit digital value is stored in adc_cdrx of the current channel and in adc_lcdr. by setting the tag bit in the extended mode register (adc_emr), adc_lcdr presents the channel number associated with the last converted data in the chnb field. the eocx and drdy bits in the interr upt status register (adc_isr) are se t. in the case of a connected pdc channel, drdy rising triggers a data request. in an y case, both eoc and drdy can trigger an interrupt. reading one adc_cdrx clea rs the correspond ing eocx bit. reading adc_lcdr clears the drdy bit. figure 40-3. eocx and drdy flag behavior if adc_cdr is not read before further incoming data is converted, the corresponding overrun error (ovrex) flag is set in the overrun status register (adc_over). new data converted when drdy is hi gh sets the govre bit in adc_isr. the ovrex flag is automatically cleared when adc_ov er is read, and govre flag is automatically cleared when adc_isr is read. read the adc_cdrx eocx drdy read the adc_lcdr chx (adc_chsr) (adc_isr) (adc_isr) write the adc_cr with start = 1 write the adc_cr with start = 1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 974 figure 40-4. eocx, govre and ovrex flag behavior warning: if the corresponding channel is disabled during a conversion or if it is disabled and then reenabled during a con- version, the associated data and the corresponding eocx and govre flags in adc_isr and ovrex flags in adc_over are unpredictable. eoc0 govre ch0 (adc_chsr) (adc_isr) (adc_isr) trigger event eoc1 ch1 (adc_chsr) (adc_isr) ovre0 (adc_over) undefined data data a data b adc_lcdr undefined data data a adc_cdr0 undefined data data b adc_cdr1 data c data c conver sion c conver sion a drdy (adc_isr) read adc_cdr1 read adc_cdr0 conver sion b rea d adc_over read adc_isr ovre1 (adc_over)
975 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.6.5 conversion triggers conversions of the active analog channels are started with a software or hardware trigger. the software trigger is provided by writing the control regist er (adc_cr) with the start bit at 1. the hardware trigger can be one of the tioa outputs of the timer counter channels. the hardware trigger is selected with the trgsel field in adc_mr. the select ed hardware trigger is enabled with the trgen bit in adc_mr. the minimum time between two consecutive trigger events must be strictly greater th an the duration time of the longest conversion sequence as configur ed in adc_mr, adc_chsr and adc_seqr1. if a hardware trigger is selected, the start of a conversion is triggered after a delay which starts at each rising edge of the selected signal. due to asynchronous handling, the delay may vary in a range of two peripheral clock periods to one adc clock period. figure 40-5. hardware trigger delay if one of the tioa outputs is selected, the corresponding timer counter channel must be programmed in waveform mode. only one start command is necessary to initiate a conversion sequence on all the channels. the adc hardware logic automatically performs the conversions on the active channels, then waits for a new request. the channel enable (adc_cher) an d channel disable (adc_chdr) re gisters permit the analog channels to be enabled or disabled independently. if the adc is used with a pdc, only the transfers of converted data from enabled channels are performed and the resulting data buffers should be interpreted accordingly. 40.6.6 sleep mode and conversion sequencer the adc sleep mode maximizes power saving by automatically deactivating the adc when it is not being used for conversions. sleep mode is selected by setting the sleep bit in adc_mr. sleep mode is managed by a conversi on sequencer, which automat ically processes the conversions of all channels at lowest power consumption. this mode can be used when the minimum period of time between two successive trigger events is greater than the startup period of the adc. see th e section ?adc characteristics? in the ?electrical characteristics?. when a start conversion request occurs, the adc is automa tically activated. as the a nalog cell requires a start-up time, the logic waits during this time and starts the conversion on the enabl ed channels. when all conversions are complete, the adc is deactivated until the next trigge r. triggers occurring during the sequence are ignored. the conversion sequencer allows automatic processing with minimum processor inte rvention and optimized power consumption. conversion sequences can be performed peri odically using a timer/counter output. by using the pdc, the periodic acquisition of seve ral samples can be processed automati cally without processor intervention. the sequence can be customized by programming adc_ seqr1 and setting the useq bit of adc_mr. the user can choose a specific order of channel s and can program up to 6 conversions by sequence. the user is free to create a personal sequence by writing channel numbers in adc_seqr1. not only can channel numbers be written in any sequence, channel numbers can be repeated several times. when the bit useq in adc_mr is set, the fields uschx in adc_seqr1 are used to define the seq uence. only enabled uschx fi elds will be part of the sequence. each uschx field has a corresponding enabl e, chx, in adc_cher (uschx field with the lowest x index is associated with bit chx of the lowest index). trigger start delay
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 976 40.6.7 comparison window the adc controller features automatic comparison functions. it compares conv erted values to a low threshold, a high threshold or both, depending on the value of the cmpmode field in the extended mode register (adc_emr). the comparison can be done on all c hannels or only on the ch annel specified in the cmpsel field of adc_emr. to compare all channels, the cmpall bit of adc_emr should be set. moreover, a filtering option can be set by writing the numb er of consecutive comparison events needed to raise the flag. this number can be written and read in the cmpfilter field of adc_emr. the flag can be read on the compe bit of adc_isr and can trigger an interrupt. the high threshold and the low threshold can be read/write in the compare window register (adc_cwr). if the comparison window is to be used with the lowres bit set in adc_ mr, the thresholds do not need to be adjusted, as the adjustment will be done internally. whether or not the lowres bit is set, thresholds must always be configured in accordance with the maximum adc resolution. 40.6.8 adc timings each adc has its own minimal startup time that is programmed through the field startup in adc_mr a minimal tracking time is necessary for the adc to guar antee the best converted final value between two channel selections. this time must be program med in the tracktim field in adc_mr. warning: no input buffer amplifier to isolate the source is included in the adc. this must be taken into consideration to program a precise value in the tracktim field. see the section ?adc characteristics? in the ?electrical characteristics?. 40.6.9 temperature sensor the temperature sensor is internally connected to channel index 7. to enable temperature measurement, the tempon bit must be set in adc_tempmr. the adc controller manages temperature measurement in several ways. the different methods of measurement depend on the configuration bits tr gen in adc_mr and ch7 in adc_chsr. temperature measurement can be triggered like the other channels by enabling its associated conversion channel index 7, writing 1 in ch7 of adc_cher. a manual start can only be performed if the trgen bit in adc_mr is cleared. when the start bit in adc_cr is set, the temperature sensor channel conversion is sc heduled together with the other enabled channels (if any). the result of the conversion is placed in the adc_cdr7 register and the associated flag eoc7 is set in adc_isr. if the trgen bit is set in adc_mr, the channel of the te mperature sensor is periodically converted together with other enabled channels. the result is placed inthe regi sters adc_lcdr and adc_cdr7. thus the temperature conversion result is part of the peripheral dma controller buffer. the temperature channel can be enabled/disabled at any time, however this ma y not be optimal for downstream processing.
977 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 40-6. non-optimized temperature conversion the temperature factor has a slow variation rate and is pot entially different from other conversion channels. as a result, the adc controller triggers the measurement differently when tempon is set in adc_tempmr but ch7 is not set in the adc_chsr. under these conditions, the measurement is triggered ever y second by means of an internal trigger generated by the rtc, always enabled and totally independent of the in ternal/external triggers . the rtc event will be processed on the next internal/external trigger event as described in figure 40-7, "optimized temperature conversion combined with classical conversions" . the internal/external trigger is selected through the trgsel field of adc_mr. in this mode of operation, the temperature sensor is only powered for a per iod of time covering the startup time and conversion time (refer to figure 40-8, "temperature conversion only" ). every second, a conversion is scheduled for channel 7 but the result of the conversion is only uploaded in adc_cdr7 and not in adc_lcdr. therefor e there is no change in the struct ure of the peripher al dma controller buffer due to the conversion of the temp erature channel; only the enabled channels are kept in the buffer. the end of conversion of the temperature channel is reported by means of eoc7 flag in adc_isr. base address (ba) ba + 0x02 adc_cdr[temp] 0 adc_cdr[0] 0 adc_cdr[0] 0 ba + 0x04 adc_cdr[0] 0 adc_cdr[temp] 0 adc_cdr[temp] 0 ba + 0x06 ba + 0x08 ba + 0x0a assuming adc_chsr[0] = 1 and adc_chsr[temp] = 1 where temp is the index of the temperature sensor channel trig.event1 dma buffer structure trig.event2 dma transfer trig.event3 adc_sel c t c t t c t c notes: adc_sel: command to the adc cell c: classic adc conversion sequence t: temperature sensor channel c t adc_chsr[temp]= 1 and adc_mr.trgen=1 adc_cdr[temp] t1 t2 t0 adc_cdr[0] c0 c1 c2 c3 c4 c5 t3 t4 t5 adc_lcdr c0 c1 c2 c3 c4 t1 t2 t0 t3 t4 t5 internal/external trigger event (trgsel defined)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 978 figure 40-7. optimized temperature conversion combined with classical conversions if tempon=1, trgen is disabled and none of the channels are enabled in adc_chsr (adc_chsr=0), then only channel 7 is conver ted at a rate of one c onversion per second (see figure 40-8, "temperature conversion only" ). this mode of operation, when combined with the slee p mode operation of the adc controller, provides a low- power mode for temperature measurement. this assumes th ere is no other adc conversion to schedule at a high sampling rate, or no other channel to convert. base address (ba) ba + 0x02 adc_cdr[0] 0 ba + 0x04 adc_cdr[0] 0 assuming adc_chsr[0] = 1 trig.event1 dma buffer structure trig.event2 dma transfer trig.event3 adc_sel c t c c t c c adc_chsr[temp]= 0 and adc_mr.trgen=1 tempon=1 adc_cdr[0] 0 internal rtc trigger event a dc_cdr[temp] t1 t2 t0 adc_cdr[0] & adc_lcdr c0 c1 c2 c3 c4 c5 1 s internal/external trigger event (trgsel defined) notes: adc_sel: command to the adc cell c: classic adc conversion sequence t: temperature sensor channel
979 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 40-8. temperature conversion only it is possible to raise a flag only if there is a predefi ned change in the temperature. the user can define a range of temperature or a threshold in the temperature com pare window register (adc_tempcwr), and the mode of comparison that can be programmed into the tempcm pmod field into adc_tempmr. these values define how the tempchg flag is raised in adc_isr. the tempchg flag can be used to generate a temperature- dependent interrupt instead of the end-of-conversion interrupt. more specifically, the inte rrupt is generated only if the temperature sensor as measured by the adc reports a temperature value below, above, inside or outside programmable thresholds (see adc_tempmr). in any case, if tempon is set, the temperature can be read at anytime in adc_cdr7 without any specific software intervention. 40.6.10 vddbu measurement the seventh adc channel (ch6) of th e adc controller is reserved for measurement of the vddbu power supply pin. for this channel, setting up, starting conversion, and other tasks must be performed the same way as for all other channels. vddbu is measured without any attenuation. this means that for vddbu greater than the voltage reference applied to the adc, the digital output clamps to the maximum value. 40.6.11 enhanced resolution mode and digital averaging function the enhanced resolution mode is enabled if lowres is clea red in adc_mr, and the osr field is set to 1 or 2 in adc_emr. the enhancement is based on a digital averaging function. freerun in adc_mr must be cleared when digital averaging is used (osr not equal to 0 in adc_emr). there is no averaging on the last index channel if the measure is triggered by an rtc event (see section 40.6.9 ?temperature sensor? ). in enhanced resolution mode, the adc controller trades conversion speed for quantization noise by averaging multiple samples, thus providing a digital low-pass filter function. if 1-bit enhancement resolution is selected (osr = 1 in adc_emr), the adc real sample rate is the maximum adc sample rate divided by 4. thus, the oversampling ratio is 4. when the 2-bit enhancement resolution is selected (osr = 2 in adc_emr), the adc real sample rate is the maximum adc sample rate divided by 16 (oversampling ratio is 16). the selected oversampling ratio applies to all enabled chan nels except for the temperature sensor channel when triggered by an rtc event. adc_sel adc_chsr= 0 and adc_mr.trgen=0 internal rtc trigger event 1 s automatic ?on? temp. sensor t t 30 us on off a dc_cdr[temp] t1 t2 t0 tempon=1 notes: adc_sel: command to the adc cell c: classic adc conversion sequence t: temperature sensor channel
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 980 the average result is valid into the adc_cdrx register (x corresponding to the index of the channel) only if eocn flag is set in adc_isr and ovren flag is cleared in ad c_over. the average result fo r all channels is valid in adc_lcdr only if drdy is set an d govre is cleared in adc_isr. note that registers adc_cdrx are not buffered. therefore, when an averaging sequence is ongoing, the value in these registers changes after each averaging sample. howe ver, overrun flags in adc_over rise as soon as the first sample of an averaging sequence is received. thus the previous averaged value is not read even if the new averaged value is not ready. as a result, when an overrun flag rises in adc_over, th e previous unread data is lost. however, the data has not been overwritten by the new averaged value, as the averaging sequence for this c hannel may still be on-going. 40.6.11.1averaging function versus trigger events the samples can be defined in different ways for the averaging function depending on the configuration of the aste bit in adc_emr and th e useq bit in adc_mr. when useq is cleared, there are two ways to generate the averaging through the trigger event. if aste is cleared in adc_emr, every trigger event generates one sa mple for each enabled channel as described in figure 40-9, "digital averaging function wavefo rms over multiple trigger events" . therefore, four trigger events are requested to get the result of averaging if osr = 1. figure 40-9. digital averaging function waveforms over multiple trigger events if aste = 1 in adc_emr and useq = 0 in adc_mr, then the sequence to be converted, defined in adc_chsr, is automatically repeated n times, where n corresponds to the oversampling ratio defined in the osr field in adc_emr. as a result, only one trigger is required to obtain the result of the averaging function as described in figure 40-9, "digital averaging function waveforms over multiple trigger events" . internal/external trigger event adc_sel 0 1 adc_emr.osr=1 aste=0, adc_chsr[1:0]= 0x3 and adc_mr.useq=0 adc_cdr[1] adc_cdr[0] ch0_0 adc_lcdr 0i1 0 1 0 1 0 1 0 1 0i2 0i3 ch0_1 0i1 ch1_0 1i1 1i2 1i3 ch1_1 1i1 eoc[0] read adc_cdr[1] ch1_1 ch0_1 eoc[1] read adc_lcdr drdy read adc_cdr[0] read adc_cdr[1] ovr[0] ch1_0 read adc_lcdr notes: adc_sel: command to the adc cell 0i1,0i2,0i3, 1i1, 1i2, 1i3 are intermediate results and ch0/1_0/1 are final results of average function.
981 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 40-10. digital averaging function waveforms on a single trigger event when useq is set, the user can define the channel sequence to be converted by configuring adc_seqrx and adc_cher so that channels are not interleaved during the averaging period. under these conditions, a sample is defined for each end of conversion as shown in figure 40-11, "digital averaging function waveforms on single trigger event, non-interleaved" . therefore, if the same channel is configured to be conv erted four times consecutively, and osr = 1 in adc_emr, the averaging result will be placed in the corresponding channel data register adc_cdrx and adc_lcdr for each trigger event. in this case, the adc real sample rate remains the ma ximum adc sample rate divided by 4 or 16, depending on osr. when useq = 1, aste = 1 and osr is different from 0, it is important to note that th e user sequence must follow a specific pattern. the user sequence must be programmed so that it generates a stream of conversion, where a given channel is successively converted with an integer multiple depending on the value of osr. up to four channels can be converted in this specific mode. when osr = 1, each channel to convert must be repeated f our times consecutively in the sequence, so the first four single bits enabled in adc_ch sr must have the associated channel i ndex programmed to the same value in adc_seq1/2. therefore, for osr =1 , a maximum of four channels can be converted. the user sequence allows a maximum of 16 conversions for each trigger event. when osr = 2, a channel to convert must be repeated 16 times consecutively in the sequence, so all fields must be enabled in the adc_chsr register, and their associated channel index programmed to the same value in adc_seq1/2. therefore, for osr = 2, only one channel ca n be converted. the user sequence allows a maximum of 16 conversions for each trigger event. osr = 3 and osr = 4 are prohibited when useq = 1 and aste = 1. internal/external trigger event adc_sel 0 adc_emr.osr=1, aste=1, adc_chsr[1:0]= 0x3 and adc_mr.useq=0 adc_cdr[1] adc_cdr[0] ch0_0 adc_lcdr 0i1 0 0i2 0i3 ch0_1 eoc[0] read adc_cdr[0] read adc_cdr[1] ch1_1 ch0_1 eoc[1] read adc_lcdr drdy 0 1 11 0 0 ch1_0 1i1 1i2 1i3 ch1_1 01 1 1 notes: adc_sel: command to the adc cell 0i1,0i2,0i3, 1i1, 1i2, 1i3 are intermediate results and ch0/1_0/1 are final results of average function.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 982 figure 40-11. digital averaging function waveforms on single trigger event, non-interleaved 40.6.11.2oversampling digital output range when an oversampling is performed, the maximum value that can be read on adc_cdrx or adc_lcdr is not the full scale value, even if the ma ximum voltage is supplied on the anal og input. this is due to the digital averaging algorithm. for example, when osr = 1, four samples are accumulated and the result is then right- shifted by 1 (divided by 2). the maximum output value carried on adc_cdrx or adc_ lcdr depends on the configuration of th field osr in adc_emr. 40.6.12 buffer structure the pdc read channel is triggered each time a new data is stored in adc_lcdr. the same data structure is repeatedly stored in adc_lcdr each time a trigger ev ent occurs. depending on the user mode of operation (adc_mr, adc_chsr, adc_seqr1), the stru cture differs. each data read to the pdc buffer, carried on a half- word (16-bit), consists of the last converted data right-aligned. when ta g is set in adc_emr, the four most significant bits carry the channel number, thus simplifying post-processing in the pdc buffer or improved checking of the pdc buffer integrity. internal/external trigger event adc_sel 0 adc_emr.osr=1, aste=1, adc_chsr[7:0]=0xff and adc_mr.useq=1 adc_cdr[1] adc_cdr[0] ch0_0 adc_lcdr 0i1 00 0i2 0i3 ch0_1 eoc[0] read adc_cdr[0] read adc_cdr[1] ch1_1 ch0_1 eoc[1] read adc_lcdr drdy 0 1 111 0 000 ch1_0 1i1 1i2 1i3 ch1_1 adc_seq1r = 0x1111_0000 notes: adc_sel: command to the adc cell 0i1,0i2,0i3, 1i1, 1i2, 1i3 are intermediate results and ch0/1_0/1 are final results of average function. table 40-4. oversampling digital output range values resolution samples shift full scale value maximum value 8-bit 1 0 255 255 10-bit 1 0 1023 1023 11-bit 4 1 2047 2046 12-bit 16 2 4095 4092
983 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 40-12. buffer structure 40.6.13 register write protection to prevent any single software error from corrupting adc behavior, certain registers in the address space can be write-protected by settin g the wpen bit in the ?adc write protection mode register? (adc_wpmr). if a write access to a write-protected re gister is detected, the wpvs flag in the ?adc write protection status register? (adc_wpsr) is set and the field wpvsrc indicates the register in which th e write access has been attempted. the wpvs bit is automatically clea red after readin g the adc_wpsr. the following registers can be write-protected: ? ?adc mode register? ? ?adc channel sequence 1 register? ? ?adc channel enable register? ? ?adc channel disable register? ? ?adc temperature sensor mode register? ? ?adc temperature compare window register? ? ?adc extended mode register? ? ?adc compare window register? ? ?adc analog control register? base address (ba) ba + 0x02 adc_cdr6 6 adc_cdr5 5 adc_cdr8 8 ba + 0x04 adc_cdr6 6 adc_cdr5 5 adc_cdr8 8 ba + 0x06 ba + 0x08 ba + 0x0a adc_cdr6 6 adc_cdr5 5 adc_cdr8 8 ba + [(n-1) * 6] ba + [(n-1) * 6]+ 0x02 ba + [(n-1) * 6]+ 0x04 assuming adc_chsr = 0x000_01600 adc_emr(tag) = 1 trig.event1 adc_cdr6 0 adc_cdr5 0 adc_cdr8 0 adc_cdr6 0 adc_cdr5 0 adc_cdr8 0 adc_cdr6 0 adc_cdr5 0 adc_cdr8 0 assuming adc_chsr = 0x000_01600 adc_emr(tag) = 0 dma buffer structure dma buffer structure trig.event2 trig.event1 trig.event2 trig.eventn trig.eventn dma transfer
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 984 40.7 analog-to-digital conver ter (adc) user interface note: if an offset is not listed in the table it must be considered as ?reserved?. table 40-5. register mapping offset register name access reset 0x00 control register adc_cr write-only ? 0x04 mode register adc_mr read/write 0x00000000 0x08 channel sequence 1 register adc_seqr1 read/write 0x00000000 0x0c reserved ? ? ? 0x10 channel enable register adc_cher write-only ? 0x14 channel disable register adc_chdr write-only ? 0x18 channel status register adc_chsr read-only 0x00000000 0x1c reserved ? ? ? 0x20 last converted data register adc_lcdr read-only 0x00000000 0x24 interrupt enable register adc_ier write-only ? 0x28 interrupt disable register adc_idr write-only ? 0x2c interrupt mask register adc_imr read-only 0x00000000 0x30 interrupt status register adc_isr read-only 0x00000000 0x34 temperature sensor mode register adc_tempmr read/write 0x00000000 0x38 temperature compare window re gister adc_tempcwr read/write 0x00000000 0x3c overrun status register adc_over read-only 0x00000000 0x40 extended mode register adc_emr read/write 0x00000000 0x44 compare window register adc_cwr read/write 0x00000000 0x50 channel data register 0 adc_cdr0 read-only 0x00000000 0x54 channel data register 1 adc_cdr1 read-only 0x00000000 ... ... ... ... ... 0x6c channel data register 7 adc_cdr7 read-only 0x00000000 0x70 - 0x90 reserved ? ? ? 0x94 analog control register adc_acr read/write 0x00000000 0x98 - 0xe0 reserved ? ? ? 0xe4 write protection mode register adc_wpmr read/write 0x00000000 0xe8 write protection status register adc_wpsr read-only 0x00000000 0xec - 0xf8 reserved ? ? ? 0xfc reserved ? ? ? 0x100 - 0x124 reserved for pdc registers ? ? ?
985 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.1 adc control register name: adc_cr address: 0x40038000 access: write-only ? swrst: software reset 0: no effect. 1: resets the adc simulating a hardware reset. ? start: start conversion 0: no effect. 1: begins analog-to-digital conversion. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????s t a r ts w r s t
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 986 40.7.2 adc mode register name: adc_mr address: 0x40038004 access: read/write this register can only be writt en if the wpen bit is cleared in ?adc write protection mode register? . ? trgen: trigger enable ? trgsel: trigger selection ? lowres: resolution 31 30 29 28 27 26 25 24 useq ? ? ? tracktim 23 22 21 20 19 18 17 16 ???? s t a r t u p 15 14 13 12 11 10 9 8 prescal 76543210 freerun ? sleep lowres trgsel trgen value name description 0 dis hardware triggers are disabled. starting a conversion is only possible by software. 1 en hardware trigger selected by trgsel field is enabled. value name description 0 adc_trig0 ? 1 adc_trig1 timer counter channel 0 output 2 adc_trig2 timer counter channel 1 output 3 adc_trig3 timer counter channel 2 output 4 adc_trig4 timer counter channel 3 output 5 adc_trig5 timer counter channel 4 output 6 adc_trig6 timer counter channel 5 output 7?r e s e r v e d value name description 0bits_10 10-bit resolution. for higher resolution by averaging, refer to section 40.7.15 ?adc extended mode register? 1 bits_8 8-bit resolution
987 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? sleep: sleep mode ? freerun: free run mode note: freerun must be set to 0 when digital averaging is used (osr differs from 0 in adc_emr register). ? prescal: prescaler rate selection f adc clock = f peripheral clock / ((prescal+1) 2) ? startup: start up time ? tracktim: tracking time tracking time = (tracktim + 1) adc clock periods value name description 0 normal normal mode: the adc core and reference vo ltage circuitry are kept on between conversions 1 sleep sleep mode: the adc core and reference voltage circuitry are off between conversions value name description 0 off normal mode 1 on free run mode: never wait for any trigger. value name description 0 sut0 0 periods of adc clock 1 sut8 8 periods of adc clock 2 sut16 16 periods of adc clock 3 sut24 24 periods of adc clock 4 sut64 64 periods of adc clock 5 sut80 80 periods of adc clock 6 sut96 96 periods of adc clock 7 sut112 112 periods of adc clock 8 sut512 512 periods of adc clock 9 sut576 576 periods of adc clock 10 sut640 640 periods of adc clock 11 sut704 704 periods of adc clock 12 sut768 768 periods of adc clock 13 sut832 832 periods of adc clock 14 sut896 896 periods of adc clock 15 sut960 960 periods of adc clock
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 988 ? useq: user sequence enable value name description 0 num_order normal mode: the controller converts channels in a simple numeric order depending only on the channel index. 1reg_order user sequence mode: the sequence respects what is defined in adc_seqr1 and can be used to convert the same channel several times.
989 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.3 adc channel sequence 1 register name: adc_seqr1 address: 0x40038008 access: read/write this register can only be writt en if the wpen bit is cleared in ?adc write protection mode register? . ? uschx: user sequence number x the sequence number x (uschx) can be programmed by the c hannel number chy where y is the value written in this field. the allowed range is 0 up to 7. so it is only possible to use the sequencer from ch0 to ch7. this register activates only if adc_mr(useq) field is set to 1. any uschx field is taken into account only if adc_chsr(chx) register field reads logical 1; else any value written in uschx does not add the corresponding channel in the conversion sequence. configuring the same value in different fields leads to mu ltiple samples of the same channel during the conversion sequence. this can be done consecutively, or not, depending on user needs. 31 30 29 28 27 26 25 24 ?? 23 22 21 20 19 18 17 16 usch6 usch5 15 14 13 12 11 10 9 8 usch4 usch3 76543210 usch2 usch1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 990 40.7.4 adc channel enable register name: adc_cher address: 0x40038010 access: write-only this register can only be writt en if the wpen bit is cleared in ?adc write protection mode register? . ? chx: channel x enable 0: no effect. 1: enables the corresponding channel. note: if useq = 1 in adc_mr, chx corresponds to the xth channel of the sequence described in adc_seqr1. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ??????? - 15 14 13 12 11 10 9 8 -------- 76543210 ch7 ch6 ? ? ch3 ch2 ch1 ch0
991 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.5 adc channel disable register name: adc_chdr address: 0x40038014 access: write-only this register can only be writt en if the wpen bit is cleared in ?adc write protection mode register? . ? chx: channel x disable 0: no effect. 1: disables the corresponding channel. warning: if the corresponding channel is disabled during a conversion or if it is disabled and then reenabled during a con- version, the associated data and corr esponding eocx and govre flags in adc_isr and ovrex flags in adc_over are unpredictable. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ??????? - 15 14 13 12 11 10 9 8 -------- 76543210 ch7 ch6 ? ? ch3 ch2 ch1 ch0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 992 40.7.6 adc channel status register name: adc_chsr address: 0x40038018 access: read-only ? chx: channel x status 0: the corresponding channel is disabled. 1: the corresponding channel is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ??????? - 15 14 13 12 11 10 9 8 -------- 76543210 ch7 ch6 ? ? ch3 ch2 ch1 ch0
993 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.7 adc last converted data register name: adc_lcdr address: 0x40038020 access: read-only ? ldata: last data converted the analog-to-digital conversion data is placed into this regi ster at the end of a conversion and remains until a new conver- sion is completed. ? chnb: channel number indicates the last converted channel when the tag option is se t to 1 in adc_emr. if the tag option is not set, chnb = 0. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 chnb ldata 76543210 ldata
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 994 40.7.8 adc interrupt enable register name: adc_ier address: 0x40038024 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? eocx: end of conversion interrupt enable x ? tempchg: temperature change interrupt enable ? drdy: data ready interrupt enable ? govre: general overrun error interrupt enable ? compe: comparison event interrupt enable ? endrx: end of receive buffer interrupt enable ? rxbuff: receive buffer full interrupt enable 31 30 29 28 27 26 25 24 ? ? ? rxbuff endrx compe govre drdy 23 22 21 20 19 18 17 16 ????t e m p c h g?? - 15 14 13 12 11 10 9 8 -------- 76543210 eoc7 eoc6 ? ? eoc3 eoc2 eoc1 eoc0
995 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.9 adc interrupt disable register name: adc_idr address: 0x40038028 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? eocx: end of conversion interrupt disable x ? tempchg: temperature change interrupt disable ? drdy: data ready interrupt disable ? govre: general overrun error interrupt disable ? compe: comparison event interrupt disable ? endrx: end of receive buffer interrupt disable ? rxbuff: receive buffer full interrupt disable 31 30 29 28 27 26 25 24 ? ? ? rxbuff endrx compe govre drdy 23 22 21 20 19 18 17 16 ????t e m p c h g?? - 15 14 13 12 11 10 9 8 -------- 76543210 eoc7 eoc6 ? ? eoc3 eoc2 eoc1 eoc0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 996 40.7.10 adc interrupt mask register name: adc_imr address: 0x4003802c access: read-only the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. ? eocx: end of conversion interrupt mask x ? tempchg: temperature change interrupt mask ? drdy: data ready interrupt mask ? govre: general overrun error interrupt mask ? compe: comparison event interrupt mask ? endrx: end of receive buffer interrupt mask ? rxbuff: receive buffer full interrupt mask 31 30 29 28 27 26 25 24 ? ? ? rxbuff endrx compe govre drdy 23 22 21 20 19 18 17 16 ????t e m p c h g?? - 15 14 13 12 11 10 9 8 -------- 76543210 eoc7 eoc6 ? ? eoc3 eoc2 eoc1 eoc0
997 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.11 adc interrupt status register name: adc_isr address: 0x40038030 access: read-only ? eocx: end of conversion x (automatically set/cleared) 0: the corresponding analog channel is disabled, or the conversi on is not finished. this flag is cleared when reading the corresponding adc_cdrx registers. 1: the corresponding analog channel is enabled and conversion is complete. ? tempchg: temperature change (cleared on read) 0: there is no comparison match (defined in adc_tempcwr) since the last read of adc_isr. 1: the temperature value reported on adc_cdr7 has changed since the last read of adc_isr, according to what is defined in adc_tempmr and adc_tempcwr. ? drdy: data ready (automatically set/cleared) 0: no data has been converted since the last read of adc_lcdr. 1: at least one data has been conv erted and is ava ilable in adc_lcdr. ? govre: general overrun error (cleared on read) 0: no general overrun error occurred since the last read of adc_isr. 1: at least one general overrun error has occurred since the last read of adc_isr. ? compe: comparison event (cleared on read) 0: no comparison event since the last read of adc_isr. 1: at least one comparison event (def ined in adc_emr and adc_cwr) has occurred since the last read of adc_isr. ? endrx: end of receive transfer (automatically set/cleared) 0: the receive counter register has not reached 0 since the last write in adc_rcr (1) or adc_rncr (1) . 1: the receive counter register has r eached 0 since the last write in adc_rcr (1) or adc_rncr (1) . ? rxbuff: receive buffer full (automatically set/cleared) 0: adc_rcr (1) or adc_rncr (1) has a value other than 0. 1: both adc_rcr (1) and adc_rncr (1) have a value of 0. note: 1. adc_rcr and adc_rncr are pdc registers. 31 30 29 28 27 26 25 24 ? ? ? rxbuff endrx compe govre drdy 23 22 21 20 19 18 17 16 ????t e m p c h g?? - 15 14 13 12 11 10 9 8 -------- 76543210 eoc7 eoc6 ? ? eoc3 eoc2 eoc1 eoc0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 998 40.7.12 adc temperature sensor mode register name: adc_tempmr address: 0x40038034 access: read/write this register can only be writt en if the wpen bit is cleared in ?adc write protection mode register? . ? tempon: temperature sensor on 0: the temperature sensor is not enabled. 1: the temperature sensor is enabl ed and the measurements are triggered. ? tempcmpmod: temperature comparison mode 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ?? t e m p c m p m o d ???t e m p o n value name description 0 low generates an event when the converted data is lower than the low threshold of the window. 1 high generates an event when the converted data is higher than the high threshold of the window. 2 in generates an event when the converted data is in the comparison window. 3 out generates an event when the converted data is out of the comparison window.
999 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.13 adc temperature compare window register name: adc_tempcwr address: 0x40038038 access: read/write this register can only be written if the wpen bit is cleared in the ?adc write protection mode register? . ? tlowthres: temperature low threshold low threshold associated to co mpare settings of adc_tempmr. ? thighthres: temperature high threshold high threshold associated to co mpare settings of adc_tempmr. 31 30 29 28 27 26 25 24 ???? t h i g h t h r e s 23 22 21 20 19 18 17 16 thighthres 15 14 13 12 11 10 9 8 ???? t l o w t h r e s 76543210 tlowthres
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1000 40.7.14 adc overrun status register name: adc_over address: 0x4003803c access: read-only ? ovrex: overrun error x 0: no overrun error on the corresponding channel since the last read of adc_over. 1: there has been an overrun error on the corres ponding channel since the last read of adc_over. note: an overrun error does not always mean that the unread data has been replaced by a new valid data. please refer to section 40.6.11 ?enhanced resolution mode and digital averaging function? for details. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 -------- 76543210 ovre7 ovre6 ? ? ovre3 ovre2 ovre1 ovre0
1001 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.15 adc extended mode register name: adc_emr address: 0x40038040 access: read/write this register can only be writt en if the wpen bit is cleared in ?adc write protection mode register? . ? cmpmode: comparison mode ? cmpsel: comparison selected channel if cmpall = 0: cmpsel indicates wh ich channel has to be compared. if cmpall = 1: no effect. ? cmpall: compare all channels 0: only the channel indicated in cmpsel field is compared. 1: all channels are compared. ? cmpfilter: compare event filtering number of consecutive compare events nec essary to raise the flag = cmpfilter+1. when programmed to 0, the flag rises as soon as an event occurs. ? osr: over sampling rate this field is active if lowres is cleared in adc_mr. note: freerun (see adc_mr) must be set to 0 when digital averaging is used. 31 30 29 28 27 26 25 24 ???????tag 23 22 21 20 19 18 17 16 ? ? ? aste ? ? osr 15 14 13 12 11 10 9 8 ? ? cmpfilter ? ? cmpall ? 76543210 cmpsel ? ? cmpmode value name description 0 low generates an event when the converted data is lower than the low threshold of the window. 1 high generates an event when the converted data is higher than the high threshold of the window. 2 in generates an event when the converted data is in the comparison window. 3 out generates an event when the converted data is out of the comparison window. value name description 0 no_average no averaging. adc sample rate is maximum. 1 osr4 1-bit enhanced resolution by averaging. adc sample rate divided by 4. 2 osr16 2-bit enhanced resolution by averaging. adc sample rate divided by 16.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1002 ? aste: averaging on single trigger event ? tag: tag of the adc_ldcr register 0: sets chnb to zero in adc_ldcr. 1: appends the channel number to t he conversion result in adc_ldcr. value name description 0 multi_trig_average the average requests several trigger events. 1 single_trig_average the average requests only one trigger event.
1003 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.16 adc compare window register name: adc_cwr address: 0x40038044 access: read/write this register can only be writt en if the wpen bit is cleared in ?adc write protection mode register? . ? lowthres: low threshold low threshold associated to compare settings of adc_emr. if lowres is set in adc_mr, only the 10 lsb of lowthr es must be programmed. the 2 lsb will be automatically dis- carded to match the value carried on adc_cdr (8-bit). ? highthres: high threshold high threshold associated to compare settings of adc_emr. if lowres is set in adc_mr, only the 10 lsb of highthres must be programme d. the 2 lsb will be automatically dis- carded to match the value carried on adc_cdr (8-bit). 31 30 29 28 27 26 25 24 ???? h i g h t h r e s 23 22 21 20 19 18 17 16 highthres 15 14 13 12 11 10 9 8 ???? l o w t h r e s 76543210 lowthres
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1004 40.7.17 adc channel data register name: adc_cdrx [x=0..7] address: 0x40038050 access: read/write ? data: converted data the analog-to-digital conversion data is placed into this regi ster at the end of a conversion and remains until a new conver- sion is completed. adc_cdrx is only loaded if the corresponding analog channel is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???? d a t a 76543210 data
1005 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.18 adc analog control register name: adc_acr address: 0x40038094 access: read/write this register can only be writt en if the wpen bit is cleared in ?adc write protection mode register? . ? irvce: internal reference voltage change enable 0 (stuck_at_default): the internal reference voltage is stuc k at the default value (see th e electrical characteristics for further details). 1 (selection): the internal referenc e voltage is defined by field irvs. ? irvs: internal reference voltage selection see the ?programmable voltage reference selection values? ta ble in the electrical characteristics for further details. ? forceref: force internal reference voltage 0: the internal voltage reference is defined. 1: the internal voltage reference is forced to vddio (onref must be cleared). ? onref: internal vo ltage reference on 0: the external pin advref defines the voltage reference. 1: the internal voltage reference is selected (forceref must be cleared). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???o n r e ff o r c e r e f??? 15 14 13 12 11 10 9 8 ???????? 76543210 ?i r v si r v c e ? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1006 40.7.19 adc write protection mode register name: adc_wpmr address: 0x400380e4 access: read/write ? wpen: write protect enable 0: disables the writ e protection if wpkey co rresponds to 0x414443 (?adc? in ascii). 1: enables the write protecti on if wpkey corres ponds to 0x414443 (?adc? in ascii). see section 40.6.13 ?register write protection? for the list of registers that can be protected. ? wpkey: write protect key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????w p e n value name description 0x414443 passwd writing any other value in this field abort s the write operation of the wpen bit. always reads as 0
1007 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 40.7.20 adc write protection status register name: adc_wpsr address: 0x400380e8 access: read-only ? wpvs: write protection violation status 0: no write protection violation has occurred since the last read of the adc_wpsr register. 1: a write protection violation has occurred since the last read of the adc_wpsr re gister. if this violation is an unauthor- ized attempt to write a pr otected register, the asso ciated violation is re ported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at whic h a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????w p v s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1008 41. energy metering analog front end (emafe) 41.1 description the energy metering analog front end peripheral (ema fe) embeds four or seven high-resolution sigma-delta analog-to-digital converters followed by sinc decimation filters running at an output data rate of 16ks/s. the two or four current measurement channels feature a low no ise programmable gain amplifier to accommodate any type of current sensor configured in any ty pe of iec/ansi-c application. one of t hese channels is dedicated to neutral current measurement to implement anti-tamper functions. the emafe also embeds a high-performance voltage reference and a die temperature sensor. the temperature characteristics of these functions are measured during manufacturing and stored in an internal read-only memory. a low-cost and efficient voltage reference temperature correction can then be implemented at software level. 41.2 embedded characteristics ? single-phase, two-phase or three-phase energy metering analog front end ? works with the atmel mcu metrology library ? compliant with class 0.2 standards (ansi c12.20-2002 and iec 62053-22) ? acquisition channels ? four or seven sigma-delta adc measurement channels: two or three voltages, two or four currents, 20-bit resolution - 102 db dynamic range ? current channels with pre-gain (x1, x2, x4, x8) ? supports shunt, current transformer and rogowsky coils ? direct connection of sensors without external preamplifier ? dedicated current channel for anti-tamper measurement ? integrated sinc decimation filters. output data rate: 16ksps ? precision voltage reference ? standard 1.2v output voltage wi th possible ex ternal bypass ? temperature drift: 10ppm typical with software correction ? factory-measured temperature drift and on-board temperature sensor to perform software correction ? integrated 2.8v ldo regulator to supply analog functions ? 3.0v to 3.6v operation, ultra-low-power at < 2.5mw per channel @3.3v ? specified over t j : -40c to +100c
1009 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 41.3 block diagram figure 41-1. functional block diagram for three-phase emafe ? adc pga adci0 <23:0> ip0 in0 diff mux 2:1 ? adc pga ? adc vp3 ip3 in3 ? adc pga ? adc vp2 ip2 in2 ? adc pga ? adc ip1 in1 vp1 vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vtemp vtemp 2.8v ldo volt age reference vddin_afe die temper ature sensor vref_afe 1k vdda gnda decimator emafe interf ace adci3 <23:0> adcv3 <23:0> decimator decimator adci2 <23:0> adcv2 <23:0> decimator decimator adci1 <23:0> adcv1 <23:0> decimator decimator vn vn vn gndref emafe 7-ch apb peripher al clock interr upt
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1010 figure 41-2. functional block diagram for two-phase emafe ? adc pga adci0 <23:0> ip0 in0 diff mux 2:1 ? adc pga ip1 in1 vdda gnda vref_afe vdda gnda vref_afe vtemp vtemp volt age reference die temper ature sensor vref_afe 1k 2.8v ldo vddin_afe vdda gnda decimator adci1 <23:0> decimator gndref emafe 4-ch ? adc vp1 adcv1 <23:0> decimator vn vdda gnda vref_afe emafe interf ace apb peripher al clock interr upt ? adc vp2 adcv2 <23:0> decimator vn vdda gnda vref_afe
1011 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 41.4 signal description note: 1. only in 7-channel emafe. table 41-1. signal description pin name i/o type function vp1 input analog voltage channel 1, positive input vp2 input analog voltage channel 2, positive input vp3 (1) input analog voltage channel 3, positive input vn input analog voltage channel 1, negative input ip0 input analog current channel 0 (tamper), positive input in0 input analog current channel 0 (tamper), negative input ip1 input analog current channel 1, positive input in1 input analog current channel 1, negative input ip2 (1) input analog current channel 2, positive input in2 (1) input analog current channel 2, negative input ip3 (1) input analog current channel 3, positive input in3 (1) input analog current channel 3, negative input vref_afe input/output analog voltage refer ence output and reference buffer input gndref ground ground voltage reference ground pin vdda input/output analog 2.8v ldo output and analog circuits power supply input gnda ground ground ground pin for low noise analog circuits and low-noise negative adc reference vddin_afe input power 2.8v ldo power supply input pin
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1012 41.5 application block diagram figure 41-3. typical three-phase application block diagram vddio 3.3v nl 3 l2l1 3k 3.3nf 3.3nf 3k 3k 3.3nf 3.3nf 3k 3k 3.3nf 3.3nf 3k 3k 3.3nf 3.3nf 3k 1f 1f 1.5 1.5 1.5 1.5 1.5 1.5 shunt 150r c.t 2000:1 c.t 2000:1 c.t 2000:1 example application diagra m for emafe in a typic al 200a (imax), 3-phas e, 4-wire sma rt meter 1k 3.3nf 165k (x10) 2.2k 1k 3.3nf 165k (x10) 2.2k 1k 3.3nf 165k (x10) 2.2k ? adc pga adci0 <23:0> ip0 in0 diff mux 2:1 ? adc pga ? adc vp3 ip3 in3 ? adc pga ? adc vp2 ip2 in2 ? adc pga ? adc ip1 in1 vp1 vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vdda gnda vref_afe vtemp vtemp 2.8v ldo volt age reference vddin_afe die temper ature sensor vref_afe 1k vdda gnda decimator emafe interf ace adci3 <23:0> adcv3 <23:0> decimator decimator adci2 <23:0> adcv2 <23:0> decimator decimator adci1 <23:0> adcv1 <23:0> decimator decimator vn vn vn gndref emafe 7-ch apb peripher al clock interr upt
1013 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 41-4. typical single-phase application block diagram 41.6 functional description 41.6.1 conversion channels the emafe has three types of acquisition channels: ? voltage channels ? current channels ? tamper and temperature channel all these channels are built around the same sigma-delta a/d converter. the voltage reference of this converter is the vref_afe pin voltage referred to ground (gnda pin). this reference voltage can be internally or externally sourced. the converter?s sampling rate is emafe_clk/4, typically 1.024 mhz. an external low-pass filter, typically a passive r-c network, is re quired at each adc input to reject frequency images around this sampling frequency (anti-alias). the emafe analog inputs are designed to sample 0v cent ered signals. as these inputs have internal esd protection devices connected to gnda, the maximum input signal level defined in the electrical characteristics must be respected to avoid leakages in these devices. this is typically 0.25v. refer to figure 41-5, "analog inputs: recommended input range" . vdd 3.3v nl 1k 3.3nf 3.3k 3.3nf 3.3nf 3.3k 3.3k 3.3nf 3.3nf 3.3k 1f 1f 1.5 1.5 shunt 150ur c.t 2000:1 example application diagra m for emafe in a typic al 100a (imax), single-phase with anti-tamper sma rt meter 2.2k 165k (x10) ? adc pga adci0 <23:0> ip0 in0 diff mux 2:1 ? adc pga ip1 in1 vdda gnda vref_afe vdda gnda vref_afe vtemp vtemp volt age reference die temper ature sensor vref_afe 1k 2.8v ldo vddin_afe vdda gnda decimator adci1 <23:0> decimator gndref emafe 4-ch ? adc vp1 adcv1 <23:0> decimator vn vdda gnda vref_afe emafe interf ace apb peripher al clock interr upt ? adc vp2 adcv2 <23:0> decimator vn vdda gnda vref_afe
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1014 figure 41-5. analog inputs: recommended input range voltage channels have single-ended inputs referred to the vn pin. this pin must be connected to a low noise ground. the user must take care that no voltage drop on the ground net is sampled by the adc by non-optimum connection of the vn pin. current channels and the tamper channel have a programmable gain amplifier (pga) to accommodate low input signals. the pga improves the dynamic range of the c hannel as the input referred noise is reduced when gain increases. the pga does not introduce any delay or bandwid th limitation on the current channels compared to the voltage channels. the channels (voltage or current) are always sampled synchronously. the input impedance of the pga depends on the programmed gain. the tamper channel features an input multiplexer to perform both the neutral current measurement and the die temperature measurement. the tamper channel has a pga to accommodate low output level current sensors. programmed gain can be changed when switching from the tamper to the die temperature sensor source. 41.6.2 voltage reference, die temperature measurement and calibration registers 41.6.2.1 voltage reference the emafe embeds an analog voltage reference with a typi cal output voltage of 1.144v. the temperature drift of the voltage reference can be approximated by a linear fit. the temperature drift is measured during manufacturing and stored in the calibration registers (rom). two measurements are made: one at a low temperature, tl, and another at a high temperature, th. at both temperat ures tl and th, vref voltage and adc_temp_out (adc i0 reading of the temperature sensor) parameters are saved. from the data obtained, the user can implement a software compensation of the voltage reference. 41.6.2.2 die temperature sensor to measure the internal die temperature, the emafe embeds a dedicated analog die temperature sensor that is multiplexed on the tamper channel (adc i0). by measur ing the die temperature periodically and by using the calibration bits, channel gain drifts over temperat ure due to the voltage reference can be corrected. +0.25v -0.25v +0.25v -0.25v ipx inx e.s .d e.s .d vdda gnda e.s .d e.s .d vdda gnda ?current? acquisition channel +0.5v -0.5v v(ipx,gnd) (0.5vpp) v(inx,gnd) (0.5vpp) v(ipx,vinx) (1vpp) +0.25v -0.25v vpx vn e.s .d e.s .d vdda gnda e.s .d e.s .d vdda gnda ? voltage? acquisition channel +0.25v -0.25v v(vpx,gnd) (0.5vpp) v(vpx,vn) (0.5vpp) gnd
1015 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42. advanced encryption standard (aes) 42.1 description the advanced encryption standard (aes) is compliant with the american fips (federal information processing standard) publication 197 specification. the aes supports all five confidential ity modes of operation fo r symmetrical key block cipher algorithms (ecb, cbc, ofb, cfb and ctr), as specified in the nist special publication 800-38a recommendation, as well as galois/counter mode (gcm) as specified in the nist special publication 800-38d recommendation . it is compatible with all these modes via peripheral dma controller channels, minimizing processor intervention for large buffer transfers. the 128-bit/192-bit/256-bit key is stored in four/s ix/eight 32-bit write-onl y aes key word registers (aes_keywr0?3). the 128-bit input data and in itialization vector (f or some modes) are each stored in four 32-bit write-only aes input data registers (aes_idatar0?3 ) and aes initialization vect or registers (aes_ivr0?3). as soon as the initialization vector, the input data and the key are configured, the encryption/decryption process may be started. then the encrypted/decrypted data are r eady to be read out on the four 32-bit aes output data registers (aes_odatar0?3) or through the pdc channels. 42.2 embedded characteristics ? compliant with fips publication 197, advanced encryption standard (aes) ? 128-bit/192-bit/256-bit cryptographic key ? 12/14/16 clock cycles encryption/decr yption processing time with a 128-bit/192-bit/256-bit cryptographic key ? double input buffer optimizes runtime ? support of the modes of operation specified in the nist special publication 800-38a and nist special publication 800-38d : ? electronic code book (ecb) ? cipher block chaining (cbc) including cbc-mac ? cipher feedback (cfb) ? output feedback (ofb) ? counter (ctr) ? galois/counter mode (gcm) ? 8, 16, 32, 64 and 128-bit data sizes possible in cfb mode ? last output data mode allows optimized me ssage authentication code (mac) generation ? connection to pdc channel capabilities optimi zes data transfers fo r all operating modes ? one channel for the receiver, one channel for the transmitter ? next buffer support
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1016 42.3 product dependencies 42.3.1 power management the aes may be clocked through the power management controller (pmc), so the programmer must first to configure the pmc to enable the aes clock. 42.3.2 interrupt the aes interface has an interrupt line co nnected to the inte rrupt controller. handling the aes interrupt requires programming the interr upt controller before configuring the aes. 42.4 functional description the advanced encryption standard (aes) specifies a fi ps-approved cryptographic algorithm that can be used to protect electronic data. the aes algorithm is a symmetri c block cipher that can encrypt (encipher) and decrypt (decipher) information. encryption converts data to an unintelligible form called ciphertext. decrypting the ciphertext converts the data back into its original form, called pl aintext. the cipher bit in the aes mode register (aes_mr) allows selection between the encryption and the decryption processes. the aes is capable of using cryptographi c keys of 128/192/256 bits to encrypt and decrypt data in blocks of 128 bits. this 128-bit/192-bit/256-bit key is defined in the aes_keywrx. the input to the encryption processes of the cbc, cfb, and ofb modes includes, in addition to the plaintext, a 128-bit data block called the initializat ion vector (iv), which must be set in the aes_ivrx. the initialization vector is used in an initial step in the encryption of a message and in the corresponding decryption of the message. the aes_ivrx are also used by the ctr mode to set the counter value. 42.4.1 operation modes the aes supports the follo wing modes of operation: ? ecb: electronic code book ? cbc: cipher block chaining ? ofb: output feedback ? cfb: cipher feedback ? cfb8 (cfb where the length of the data segment is 8 bits) ? cfb16 (cfb where the length of the data segment is 16 bits) ? cfb32 (cfb where the length of the data segment is 32 bits) ? cfb64 (cfb where the length of the data segment is 64 bits) ? cfb128 (cfb where the length of the data segment is 128 bits) ? ctr: counter ? gcm: galois/counter mode the data pre-processing, post-processing and data chaining for the concerned modes are automatically performed. refer to the nist special publication 800-38a and nist special publication 800-38d for more complete information. these modes are selected by setting the op mod field in the aes_mr. table 42-1. peripheral ids instance id aes 36
1017 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 in cfb mode, five data sizes are possi ble (8, 16, 32, 64 or 128 bits), confi gurable by means of the cfbs field in the aes_mr ( section 42.5.2 ? aes mode register? on page 1031 ). in ctr mode, the size of the block counter embedded in the module is 16 bits. therefore, there is a rollover after processing 1 megabyte of data. if the file to be processed is greater than 1 megabyte, this file must be split into fragments of 1 megabyte or less for the first fragment if the initial value of the counte r is greater than 0. prior to loading the first fragment into aes_id atarx, aes_ivrx must be fully programmed with the initial counter value. for any fragment, after the transfer is completed and prior to transferring the next fr agment, aes_ivrx must be programmed with the appropriate counter value. if the initial value of the counter is greater than 0 and the data buffer size to be processed is greater than 1 megabyte, the size of the first fragment to be processed must be 1 megabyte minus 16x(i nitial value) to prevent a rollover of the internal 1-bit counter. to have a sequential increment, the counter value must be programmed with the value programmed for the previous fragment + 2 16 (or less for the first fragment). all aes_ivrx fields must be prog rammed to take into account the possible ca rry propagation. 42.4.2 double input buffer the aes_idatarx can be double-buffered to reduce the runtim e of large files. this mode allows writing a new message block when the previous message block is being processed. this is only possible when dma accesses are performed (smod = 0x2). the dualbuff bit in the aes_mr must be se t to ?1? to access the double buffer. 42.4.3 start modes the smod field in the aes_mr allows selection of the encryption (or decryption) start mode. 42.4.3.1 manual mode the sequence order is as follows: ? write the aes_mr with all required fields, in cluding but not limited to smod and opmod. ? write the 128-bit/192-bit/256 -bit key in the aes_keywrx. ? write the initialization vector (or counter) in the aes_ivrx. note: the aes_ivrx concern all modes except ecb. ? set the bit datrdy (data ready) in the aes interrupt enable register (aes_ier), depend ing on whether an interrupt is required or not at the end of processing. ? write the data to be encrypted/decrypted in the authorized aes_idatarx (see table 42-2 ). table 42-2. authorized input data registers operation mode input data registers to write ecb all cbc all ofb all 128-bit cfb all 64-bit cfb aes_idatar0 and aes_idatar1 32-bit cfb aes_idatar0 16-bit cfb aes_idatar0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1018 note: in 64-bit cfb mode, writing to aes_idatar2 and aes_idatar 3 is not allowed and may lead to errors in processing. note: in 32, 16, and 8-bit cfb modes, writing to aes_idata r1, aes_idatar2 and aes_idatar3 is not allowed and may lead to errors in processing. ? set the start bit in the aes control register (aes_cr) to begin the encryption or the decryption process. ? when processing completes, the datrdy flag in the aes interrupt st atus register (aes_is r) is raised. if an interrupt ha s been enabled by sett ing the datrdy bit in the aes_ier, the interrupt line of the aes is activated. ? when software reads one of the aes_odatarx, the datrdy bit is automatically cleared. 42.4.3.2 auto mode the auto mode is similar to the manual one, except that in this mode, as soon as the correct number of aes_idatarx is written, processing is automa tically started without any action in the aes_cr. 42.4.3.3 pdc mode the peripheral dma controller (pdc) can be used in association with the aes to perform an encryption/decryption of a buffer without any action by software during processing. the field smod in the aes_mr must be configured to 0x2. the sequence order is as follows: ? write the aes_mr with all required fields, in cluding but not limited to smod and opmod. ? write the key in the aes_keywrx. ? write the initialization vector (or counter) in the aes_ivrx. note: the aes_ivrx concern all modes except ecb. ? set the transmit pointer register (aes_tpr) to the address where the data buffer to encrypt/decrypt is stored and the receive pointe r register (aes_rpr) where it must be encrypted/decrypted. note: transmit and receive buffers can be identical. ? set the transmit and the receive counter regi sters (aes_tcr and aes_rcr) to the same value. this value must be a multiple of the data transfer type size (see table 42-3 ?data transfer type for the different operation modes? ). note: the same requirements ar e necessary for the next pointer(s) and co unter(s) of the pdc (aes_tnpr, aes_rnpr, aes_tncr, aes_rncr). ? if not already done, set the bit endrx (or rxbuff if the next pointers and counters are used) in the aes_ier, depending on whether an interrupt is required or not at the end of processing. ? enable the pdc in transmis sion and reception to start the processing (aes_ptcr). when the processing completes, the endrx (or rxbuff) flag in the aes_isr is raised. if an interrupt has been enabled by setting the co rresponding bit in the aes_ier, the in terrupt line of the aes is activated. when pdc is used, the data size to tr ansfer (byte, half-word or word) de pends on the aes mode of operations. this size is automatica lly configured by the aes. 8-bit cfb aes_idatar0 ctr all gcm all table 42-2. authorized input data registers operation mode input data registers to write
1019 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42.4.4 last output data mode this mode is used to generate cryptographic checksums on data (mac) by means of cipher block chaining encryption algorithm (cbc-mac algorithm for example). after each end of encryption/decryption, the output data are available either on the aes_odatarx for manual and auto mode or at the address specified in the receive buffer pointer for pdc mode (see table 42-4 ?last output data mode behavior versus start modes? ). the last output data (lod) bit in the aes_mr allows retrieval of only the last data of several encryption/decryption processes. therefore, there is no need to define a read buffer in pdc mode. this data are only ava ilable on the aes_odatarx. 42.4.4.1 manual and auto modes 42.4.4.2 if aes_mr.lod = 0 the datrdy flag is cleared when at l east one of the aes_odatarx is read (see figure 42-1 ). figure 42-1. manual and auto modes with aes_mr.lod = 0 if the user does not want to read the aes_odatarx between each encryptio n/decryption, the datrdy flag will not be cleared. if the datrdy flag is not clear ed, the user cannot know the end of the following encryptions/decryptions. table 42-3. data transfer type for the different operation modes operation mode data transfer type ecb word cbc word ofb word cfb 128-bit word cfb 64-bit word cfb 32-bit word cfb 16-bit half-word cfb 8-bit byte ctr word gcm word encryption or decryption process read the aes_odatarx write start bit in aes_cr (manual mode) datrdy write aes_idatarx register(s) (auto mode) or
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1020 42.4.4.3 if aes_mr.lod = 1 this mode is optimized to pr ocess aes cpc-mac operating mode. the datrdy flag is cleared when at least one aes_idatar is written (see figure 42-2 ). no more aes_odatar reads are necessary between consecutive encryptions/decryptions. figure 42-2. manual and auto modes with aes_mr.lod = 1 42.4.4.4 pdc mode 42.4.4.5 if aes_mr.lod = 0 this mode may be used for all aes operating modes except cbc-mac where aes_mr.lod = 1 mode is recommended. the end of the encryption/decryption is indicated when the endrx (or rxbuff) flag is raised (see figure 42-3 ). figure 42-3. pdc transfer with aes_mr.lod = 0 42.4.4.6 if aes_mr.lod = 1 this mode is optimized to pr ocess aes cbc-mac operating mode. the user must first wait for the endtx (or txbufe) flag to be raised, then for datrdy to ensure that the encryption/decryption is completed (see figure 42-4 ). in this case, no receive buffers are required. the output data are only available on the aes_odatarx. write aes_idatarx register(s) write start bit in aes_cr (manual mode) write aes_idatarx register(s) (auto mode) or encryption or decryption process datrdy enable pdc channels (receive and transmit channels) multiple encryption or decryption processes endrx (or rxbuff) endtx (or txbufel) message fully processed (cipher or decipher) last block can be read write accesses into aes_idatarx read accesses into aes_odatarx
1021 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 42-4. pdc transfer with aes_mr.lod = 1 table 42-4 summarizes the different cases. note: 1. depending on the mode, there are other ways of clearing the datrdy flag. see ?aes interrupt status register? on page 1036 . warning: in pdc mode, reading the aes_odatarx before the last data transfer may lead to unpredictable results. datrdy enable pdc channels (receive and transmit channels) multiple encryption or decryption processes endtx (or txbufe) message fully processed (cipher or decipher) mac result can be read write accesses into aes_idatarx message fully transferred table 42-4. last output data mode behavior versus start modes sequence manual and auto modes pdc mode aes_mr.lod = 0 aes_mr.lod = 1 a es_mr.lod = 0 aes_mr.lod = 1 datrdy flag clearing condition (1) at least one aes_odatar must be read at least one aes_idatar must be written not used managed by the pdc end of encryption/decryption notification datrdy datrdy endrx (or rxbuff) endtx (or txbufe) then datrdy encrypted/decrypted data result location in the aes_odatarx in the aes_odatarx at the address specified in the aes_rpr in the aes_odatarx
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1022 42.4.5 galois/counter mode (gcm) 42.4.5.1 description gcm comprises the aes engine in ctr mode along with a universal hash function (ghash engine) that is defined over a bina ry galois field to pr oduce a message aut hentication tag (t he aes ctr engine and the ghash engine are depicted in figure 42-5 ?gcm block diagram? on page 1022 ). the ghash engine processes data packets after the aes operation. gcm provides assurance of the confidentiality of data through the aes counter mode of operation for encryption. authenticity of the confidential data is assured through the ghash engine. gcm can also provide assurance of data that is not encrypted. refer to the nist special publication 800-38d for more complete information. gcm processing is computed on 128-bit input data fields. there is no support for unaligned data. the aes key length can be whatever length is supported by the aes module. figure 42-5. gcm block diagram gcm can be used with or without the pdc master. me ssages may be processed as a single complete packet of data or they may be broken into multiple packets of data over time. the recommended programming procedure when using pdc is described in section 42.4.5.3 . ghash engine aes ctr engine counter 1 counter 0 counter n incr 32 incr 32 plaintext 1 auth tag(t) len(aad) || len(c) plaintext n ciphertext 1 ciphertext n gf 128 mult(h) gf 128 mult(h) gf 128 mult(h) gf 128 mult(h) cipher(key) cipher(key) cipher(key) (aes_aadlenr, aes_clenr) (aes_tagrx) (aes_ghashrx) (aes_ivrx) (aes_ctrr) (aes_idatarx) (aes_idatarx) (aes_ctrr) (aes_ghashrx) aad 1 gf 128 mult(h) (aes_gcmhrx) (1) aad n (aes_ghashrx) (aes_idatarx) (aes_idatarx) (aes_keywrx) notes: 1. optional
1023 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42.4.5.2 key writing and automatic hash subkey calculation whenever a new key (aes_keywrx) is written to the hardware, two automatic actions are processed: ? gcm hash subkey h generation?the gcm hash subkey ( h ) is automatically generated. the gcm hash subkey generation must be complete before doing any other ac tion. the datrdy bit of the aes_isr indicates when the subkey generation is complete ( with interrupt if configured). the gcm hash subkey calculation is proce ssed with the formula h = cipher(key, <128 bits to zero>. the generated gcm h value is then available in the aes_gcmhrx. if the application software requires a specific hash subkey, the automatically generated h value can be overwrit ten in the aes_gcmhrx. the aes_gcmhrx can be written afte r the end of the hash subkey generation (s ee aes_isr.datrdy) and prior to starting the input data feed. ? aes_ghashrx clear?the aes_ghashrx ar e automatically cleared. if a hash initial value is needed for the ghash it must be written to the aes_ghashrx: ? after a write to aes_keywrx, if any ? before starting the input data feed 42.4.5.3 gcm processing gcm processing comprises three phases: 1. processing the additional authenticated data ( aad ), hash computation only. 2. processing the ciphertext ( c ), hash computation + ciphering/deciphering. 3. generating the tag using length of aad , length of c and j 0 (see nist documentation for details). the tag generation can be done either automatically, after the end of aad / c processing if tag_en bit is set in the aes_mr or done manuall y, using the ghash field in aes_ghashrx (see section 42.4.5.4 and section 42.4.5.7 for details). 42.4.5.4 processing a complete message with tag generation use this procedure only if j 0 four lsb bytes 0xffffffff. note: in the case where j 0 four lsb bytes = 0xffffffff or if the value is unknown, use the procedure described in section 42.4.5.5 ?processing a complete message without tag generation? followed by the procedure in section 42.4.5.7 ?manual gcm tag generation? . figure 42-6. full message alignment to process a complete message with tag generation, perform the following steps: 1. in aes_mr set opmod to gcm and gtagen to ?1? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait until datrdy bi t of aes_isr is set (gcm hash subkey generation complete); use interrupt if needed. see section 42.4.5.2 ?k ey writing and automatic hash subkey calculation? for details. 3. calculate the j 0 value as described in nist documentation j 0 = iv || 0 31 || 1 when len( iv ) = 96 and j 0 = ghash h ( iv || 0 s+64 || [len( iv )] 64 ) if len(iv ) 96. see section 42.4.5.8 ?processing a message with only aad (ghashh)? for j 0 generation. 4. set iv in aes_ivrx with inc32( j 0 ) ( j 0 + 1 on 32 bits). 5. set aadlen field in aes_aadlenr and clen field in aes_clenr. aad c (text) 16-byte boundaries padding padding aadlen clen
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1024 6. fill the idata field of aes_idatarx with the message to process according to the smod configuration used. if manual mode or auto mode is used, the dat rdy bit indicates when the data have been processed (however, no output data are generated when processing aad ). 7. wait for tagrdy to be set (use interrupt if needed), then read the tag field of aes_tagrx to obtain the authentication tag of the message. 42.4.5.5 processing a complete message without tag generation processing a message without generating the tag can be used to customize the tag generation, or to process a fragmented message. to manually generate the gcm tag see section 42.4.5.7 . to process a complete message without tag generation, perform the following steps: 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait until datrdy bi t of aes_isr is set (gcm hash subkey generation complete); use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or ov erwritten with specific valu e in the aes_gcmhrx (see section 42.4.5.2 ?key writing and automatic ha sh subkey calculation? for details). 3. calculate the j 0 value as described in nist documentation j 0 = iv || 0 31 || 1 when len( iv ) = 96 and j 0 = ghash h ( iv || 0 s+64 || [len( iv )] 64 ) if len( iv ) 96. see section 42.4.5.8 for j 0 generation example when len( iv ) 96. 4. set iv in aes_ivrx with inc32( j 0 ) ( j 0 + 1 on 32 bits). 5. set aadlen field in aes_aadlenr and clen field in aes_clenr. 6. fill the idata field of aes_idatarx with the message to process according to the smod configuration used. if manual mode or auto mode is used, the dat rdy bit indicates when the data have been processed (however, no output data are generated when processing aad ). 7. make sure the last output data have been read if clen 0 (or wait for datrdy), then read the ghash field of aes_ghashrx to obtain the hash value after the last processed data. 42.4.5.6 processing a fragmented message without tag generation if needed, a message can be processed by fragments, in such case automatic gcm tag generation is not supported. to process a message by fragments, perform the following steps: ? first fragment: 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait for datrdy bit of aes_isr to be set (gcm hash subkey generation complete); use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or ov erwritten with specific valu e in the aes_gcmhrx (see section 42.4.5.2 ?key writing and automatic ha sh subkey calculation? for details). 3. calculate the j 0 value as described in nist documentation j 0 = iv || 0 31 || 1 when len( iv ) = 96 and j 0 = ghash h ( iv || 0 s+64 || [len( iv )] 64 ) if len( iv ) 96. see section 42.4.5.8 for j 0 generation example when len( iv ) 96. 4. set iv in aes_ivrx with inc32( j 0 ) ( j 0 + 1 on 32 bits). 5. set aadlen field in aes_aadlenr and clen field in aes_clenr according to t he length of the first fragment, or set the fields with the full message length, both configurations work. 6. fill the idata field of aes_idatarx with the first frag ment of the message to pr ocess (aligned on 16-byte boundary) according to the smod configuration used. if manual mode or auto mode is used the datrdy bit indicates when the data have been processed (however, no output data are generated when processing aad ). 7. make sure the last output data have been read if th e fragment ends in c phase (or wait for datrdy if the fragment ends in aad phase), then read the ghash field of aes_ ghashrx to obtain the value of the hash
1025 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 after the last processed data and fi nally read the ctr field of the aes_ct r to obtain the value of the ctr encryption counter (not needed when the fragment ends in aad phase). ? next fragment (or last fragment): 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait until datrdy bi t of aes_isr is set (gcm hash subkey generation complete); use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or ov erwritten with specific valu e in the aes_gcmhrx (see section 42.4.5.2 ?key writing and automatic ha sh subkey calculation? for details). 3. set iv in aes_ivrx with: ? if the first block of the fragment is a block of additional auth enticated data, set iv in aes_ivrx with the j0 initial value ? if the first block of the fragment is a block of plaintext data, set iv in aes_ivrx with a value constructed as follows: ?lsb96(j0) || ctr? value, (96 bit lsb of j0 concatenated with saved ctr value from previous fragment). 4. set aadlen field in aes_aadlenr and clen field in aes_clenr according to the length of the current fragment, or set the fields with the remainin g message length, both configurations work. 5. fill the ghash field of aes_ghashrx with the value stored after th e previous fragment. 6. fill the idata field of aes_idatarx with the current fragment of the message to process (aligned on 16 byte boundary) according to the smod configuration used. if manual mode or auto mode is used, the datrdy bit indicates when the data have been processed (however, no output data are generated when processing aad ). 7. make sure the last output data have been read if th e fragment ends in c phase (or wait for datrdy if the fragment ends in aad phase), then read the ghash field of aes_ ghashrx to obtain the value of the hash after the last processed data and fi nally read the ctr field of the aes_ct r to obtain the value of the ctr encryption counter (not needed when the fragment ends in aad phase). note: step 1 and 2 are required only if the val ue of the concerned registers has been modified. once the last fragment ha s been processed, the ghash value will allow manual generation of the gcm tag (see section 42.4.5.7 for details). 42.4.5.7 manual gcm tag generation this section describes the last steps of the gcm tag generation. the manual gcm tag generation is used to complete the gcm tag generation when the message has been processed without tag generation. note: the message processing without ta g generation must be finished before processing the manual gcm tag generation. to generate a gcm tag manually, perform the following steps: processing s = ghash h ( aad || 0 v || c || 0 u || [len( aad )] 64 || [len( c )] 64 ): 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait for datrdy bit of aes_isr to be set (gcm hash subkey generation complete); use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or ov erwritten with specific valu e in the aes_gcmhrx (see section 42.4.5.2 ?key writing and automatic ha sh subkey calculation? for details). 3. set aadlen field to 0x10 (16 byte s) in aes_aadlenr and clen field to ?0? in aes_clenr. this will allow running a single ghash h on a 16-byte input data (see figure 42-7 ). 4. fill the ghash field of aes_ghashrx with the state of the ghash field stored at the end of the message processing.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1026 5. fill the idata field of aes_idatarx accord ing to the smod configuration used with ?len( aad ) 64 || len( c ) 64 ? value as described in the nist documentation and wa it for datrdy to be set; use interrupt if needed. 6. read the ghash field of aes_ghashrx to obtain the current value of the hash. processing t = gctr k ( j 0 , s ): 7. in aes_mr set opmod to ctr (con figuration as usual for the rest). 8. set the iv field in aes_ivrx with ? j 0 ? value. 9. fill the idata field of aes_idatarx with the ghash valu e read at step 6 and wait for datrdy to be set (use interrupt if needed). 10. read the odata field of aes_odatarx to obtain the gcm tag value. note: step 4 is optional if the ghash field is to be filled with value ?0? (0 length packet for instance). 42.4.5.8 processing a message with only aad (ghash h ) figure 42-7. single ghash h block diagram (aadlen 0x10 and clen = 0) it is possible to process a message with only aad setting the clen field to ?0? in the aes_clenr, this can be used for j 0 generation when len( iv ) 96 for instance. example: processing j 0 when len( iv ) 96 to process j 0 = ghash h ( iv || 0 s+64 || [len( iv )] 64 ) perform the following steps: 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait until datrdy bi t of aes_isr is set (gcm hash subkey generation complete); use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or ov erwritten with specific valu e in the aes_gcmhrx (see section 42.4.5.2 ?key writing and automatic ha sh subkey calculation? for details). 3. set aadlen field with ?len( iv || 0 s+64 || [len( iv )] 64 )? in aes_aadlenr and clen field to ?0? in aes_clenr. this will allow running a ghash h only. 4. fill the idata field of aes_idat arx with the messag e to process ( iv || 0 s+64 || [len( iv )] 64 ) according to the smod configuration used. if manual mode or auto mode is used, the datrdy bit indicates when a ghash h step is over (use interrupt if needed). 5. read the ghash field of aes_ghashrx to obtain the j 0 value. note: the ghash value can be overwritten at any time by writing t he ghash field value of aes_ghashrx, used to perform a ghash h with an initial value for ghash (write ghash field between step 3 and step 4 in this case). 42.4.5.9 processing a single gf 128 multiplication the aes can also be used to process a single multip lication in the galois field on 128 bits (gf 128 ) using a single ghash h with custom h value (see figure 42-7 ). to run a gf 128 multiplication (a x b) perform the following steps: idata ghash ghash gf 128 mult(h)
1027 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set aadlen field with 0x10 (16 by tes) in aes_aadlenr and clen fiel d to ?0? in aes_clenr. this will allow running a single ghash h . 3. fill the h field of the aes_gcmhrx with b value. 4. fill the idata field of aes_idatarx with the a value according to the smod conf iguration used. if manual mode or auto mode is used, the datrdy bit indicates when a ghash h computation is over (use interrupt if needed). 5. read the ghash field of aes_ghashrx to obtain the result. note: the ghash field of aes_ghashrx can be initialized wi th a value c between step 3 and step 4 to run a ((a xor c) x b) gf 128 multiplication. 42.4.6 security features 42.4.6.1 unspecified register access detection when an unspecified register access occurs, the urad flag in the aes_isr is raised. it s source is then reported in the unspecified register access type (urat) field. only the last unspecified register access is available through the urat field. several kinds of unspecified register accesses can occur: ? input data register written during the data processing when smod = idatar0_start ? output data register read during data processing ? mode register written during data processing ? output data register read during sub-keys generation ? mode register written during sub-keys generation ? write-only register read access the urad bit and the urat field can only be reset by the swrst bit in the aes_cr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1028 42.5 advanced encryption sta ndard (aes) user interface table 42-5. register mapping offset register name access reset 0x00 control register aes_cr write-only ? 0x04 mode register aes_mr read/write 0x0 0x08?0x0c reserved ? ?? 0x10 interrupt enable re gister aes_ier write-only ? 0x14 interrupt disable r egister aes_idr write-only ? 0x18 interrupt mask register aes_imr read-only 0x0 0x1c interrupt status register aes_isr read-only 0x0000001e 0x20 key word register 0 aes_keywr0 write-only ? 0x24 key word register 1 aes_keywr1 write-only ? 0x28 key word register 2 aes_keywr2 write-only ? 0x2c key word register 3 aes_keywr3 write-only ? 0x30 key word register 4 aes_keywr4 write-only ? 0x34 key word register 5 aes_keywr5 write-only ? 0x38 key word register 6 aes_keywr6 write-only ? 0x3c key word register 7 aes_keywr7 write-only ? 0x40 input data register 0 aes_idatar0 write-only ? 0x44 input data register 1 aes_idatar1 write-only ? 0x48 input data register 2 aes_idatar2 write-only ? 0x4c input data register 3 aes_idatar3 write-only ? 0x50 output data register 0 aes_odatar0 read-only 0x0 0x54 output data register 1 aes_odatar1 read-only 0x0 0x58 output data register 2 aes_odatar2 read-only 0x0 0x5c output data register 3 aes_odatar3 read-only 0x0 0x60 initialization vector re gister 0 aes_ivr0 write-only ? 0x64 initialization vector re gister 1 aes_ivr1 write-only ? 0x68 initialization vector re gister 2 aes_ivr2 write-only ? 0x6c initialization vector re gister 3 aes_ivr3 write-only ? 0x70 additional authenti cated data length regi ster aes_aadlenr read/write ? 0x74 plaintext/cipher text length register aes_clenr read/write ? 0x78 gcm intermediate hash word register 0 aes_ghashr0 read/write ? 0x7c gcm intermediate hash word register 1 aes_ghashr1 read/write ? 0x80 gcm intermediate hash word register 2 aes_ghashr2 read/write ? 0x84 gcm intermediate hash word register 3 aes_ghashr3 read/write ? 0x88 gcm authenti cation tag word register 0 aes_tagr0 read-only ? 0x8c gcm authenticati on tag word register 1 aes_tagr1 read-only ?
1029 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 0x90 gcm authenti cation tag word register 2 aes_tagr2 read-only ? 0x94 gcm authenti cation tag word register 3 aes_tagr3 read-only ? 0x98 gcm encryption counter value regist er aes_ctrr read-only ? 0x9c gcm h word register 0 aes_gcmhr0 read/write ? 0xa0 gcm h word register 1 aes_gcmhr1 read/write ? 0xa4 gcm h word register 2 aes_gcmhr2 read/write ? 0xa8 gcm h word register 3 aes_gcmhr3 read/write ? 0xac reserved ? ?? 0xb0?0xfc reserved ? ?? 0x100?0x124 reserved for the pdc ? ?? table 42-5. register mapping (continued) offset register name access reset
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1030 42.5.1 aes control register name: aes_cr address: 0x40000000 access: write-only ? start: start processing 0: no effect 1: starts manual encryption/decryption process. ? swrst: software reset 0: no effect. 1: resets the aes. a so ftware triggered hardware reset of the aes in terface is performed. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????s w r s t 76543210 ???????s t a r t
1031 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42.5.2 aes mode register name: aes_mr address: 0x40000004 access: read/write ? cipher: processing mode 0: decrypts data. 1: encrypts data. ? gtagen: gcm automatic tag generation enable 0: automatic gcm tag generation disabled. 1: automatic gcm tag generation enabled. ? dualbuff: dual input buffer ? procdly: processing delay processing time = n (procdly + 1) where n = 10 when keysize = 0 n = 12 when keysize = 1 n = 14 when keysize = 2 the processing time represents the number of clock c ycles that the aes needs in order to perform one encryption/decryption. note: the best performance is achieved with procdly equal to 0. ? smod: start mode 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ckey ? cfbs 15 14 13 12 11 10 9 8 lod opmod keysize smod 76543210 procdly dualbuff ? gtagen cipher value name description 0x0 inactive aes_idatarx cannot be written during processing of previous block. 0x1 active aes_idatarx can be written during processing of previous block when smod = 0x2. it speeds up the overall runtime of large files. value name description 0x0 manual_star t manual mode 0x1 auto_start auto mode 0x2 idatar0_start aes_idatar0 access only auto mode
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1032 values which are not listed in the table must be considered as ?reserved?. if a pdc transfer is used, conf igure smod to 0x2. refer to section 42.4.3.3 ?pdc mode? for more details. ? keysize: key size values which are not listed in the table must be considered as ?reserved?. ? opmod: operation mode values which are not listed in the table must be considered as ?reserved?. for cbc-mac operating mode, please set opmod to cbc and lod to 1. ? lod: last output data mode 0: no effect. after each end of encryption/decryption, t he output data are available either on th e output data registers (manual and auto modes) or at the addre ss specified in the receive pointer register (aes_rp r) for pdc mode. in manual and auto modes, the datrdy flag is cleared wh en at least one of the output data registers is read. 1: the datrdy flag is cleared when at leas t one of the input data registers is written. no more output data register reads is necessary between consecutive encr yptions/decryptions (see ?last output data mode? on page 1019 ). warning : in pdc mode, reading to the output data registers before the last data encryption/decryption process may lead to unpredictable results. ? cfbs: cipher feedback data size values which are not listed in table must be considered as ?reserved?. value name description 0x0 aes128 aes key size is 128 bits 0x1 aes192 aes key size is 192 bits 0x2 aes256 aes key size is 256 bits value name description 0x0 ecb ecb: electronic code book mode 0x1 cbc cbc: cipher block chaining mode 0x2 ofb ofb: output feedback mode 0x3 cfb cfb: cipher feedback mode 0x4 ctr ctr: counter mode (16-bit internal counter) 0x5 gcm gcm: galois/counter mode value name description 0x0 size_128bit 128-bit 0x1 size_64bit 64-bit 0x2 size_32bit 32-bit 0x3 size_16bit 16-bit 0x4 size_8bit 8-bit
1033 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? ckey: key 42.5.3 aes interrupt enable register name: aes_ier address: 0x40000010 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? datrdy: data ready interrupt enable ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? rxbuff: receive buffer full interrupt enable ? txbufe: transmit buffer empty interrupt enable ? urad: unspecified register access detection interrupt enable ? tagrdy: gcm tag ready interrupt enable value name description 0xe passwd this field must be written with 0xe the first ti me that aes_mr is programmed. for subsequent programming of the aes_mr, any value can be written, includi ng that of 0xe. always reads as 0. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????t a g r d y 15 14 13 12 11 10 9 8 ???????u r a d 76543210 ? ? ? txbufe rxbuff endtx endrx datrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1034 42.5.4 aes interrupt disable register name: aes_idr address: 0x40000014 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? datrdy: data ready interrupt disable ? endrx: end of receive buffer interrupt disable ? endtx: end of transmit buffer interrupt disable ? rxbuff: receive buffer full interrupt disable ? txbufe: transmit buffer empty interrupt disable ? urad: unspecified register access detection interrupt disable ? tagrdy: gcm tag read y interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????t a g r d y 15 14 13 12 11 10 9 8 ???????u r a d 76543210 ? ? ? txbufe rxbuff endtx endrx datrdy
1035 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42.5.5 aes interrupt mask register name: aes_imr address: 0x40000018 access: read-only the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. ? datrdy: data ready interrupt mask ? endrx: end of receive buffer interrupt mask ? endtx: end of transmit buffer interrupt mask ? rxbuff: receive buffer full interrupt mask ? txbufe: transmit buff er empty interrupt mask ? urad: unspecified register access detection interrupt mask ? tagrdy: gcm tag ready interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????t a g r d y 15 14 13 12 11 10 9 8 ???????u r a d 76543210 ? ? ? txbufe rxbuff endtx endrx datrdy
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1036 42.5.6 aes interrupt status register name: aes_isr address: 0x4000001c access: read-only ? datrdy: data ready 0: output data not valid. 1: encryption or decryption process is completed. datrdy is cleared when a manual encry ption/decryption occurs (start bit in aes_cr) or when a software triggered hardware reset of the aes interface is performe d (swrst bit in aes_cr). aes_mr.lod = 0 : in manual and auto mode, the datrdy flag can also be cleared when at least one of the output data registers is read. in pdc mode, datrdy is set and cleared automatically. aes_mr.lod = 1 : in manual and auto mode, the datrdy flag can also be cleared when at least one of the input data registers is written. in pdc mode, datrdy is set and cleared automatically. ? endrx: end of rx buffer 0: the receive counter register has not reach ed 0 since the last writ e in aes_rcr or aes_rncr. 1: the receive counter register has reached 0 since the last write in aes_rcr or aes_rncr. note: this flag must be used only in pdc mode with aes_mr.lod bit cleared. ? endtx: end of tx buffer 0: the transmit counter register has not reached 0 since the last write in aes_tcr or aes_tncr. 1: the transmit counter regist er has reached 0 since the la st write in aes_tcr or aes_tncr. note: this flag must be used only in pdc mode with aes_mr.lod bit set. ? rxbuff: rx buffer full 0: aes_rcr or aes_rncr has a value other than 0. 1: both aes_rcr and aes_ rncr have a value of 0. note: this flag must be used only in pdc mode with aes_mr.lod bit cleared. ? txbufe: tx buffer empty 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????t a g r d y 15 14 13 12 11 10 9 8 u r a t ???u r a d 76543210 ? ? ? txbufe rxbuff endtx endrx datrdy
1037 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 0: aes_tcr or aes_tncr has a value other than 0. 1: both aes_tcr and aes_tncr have a value of 0. note: this flag must be used only in pdc mode with aes_mr.lod bit set. ? urad: unspecified register access detection status 0: no unspecified register access ha s been detected since the last swrst. 1: at least one unspecified register acce ss has been detected since the last swrst. urad bit is reset only by the swrst bit in the aes_cr. ? urat: unspecified register access only the last unspecified register access type is available through the urat field. urat field is reset only by the swrst bit in the aes_cr. ? tagrdy: gcm tag ready 0: gcm tag is not valid. 1: gcm tag generation is complete (cleared reading gcm tag, starting another processing or when writing a new key). value name description 0x0 idr_wr_processing input data regi ster written during the data processing when smod = 0x2 mode. 0x1 odr_rd_processing output data register read during the data processing. 0x2 mr_wr_processing mode register written during t he data processing. 0x3 odr_rd_subkgen output data register read during the sub-keys generation. 0x4 mr_wr_subkgen mode register writ ten during the sub-keys generation. 0x5 wor_rd_access write-only register read access.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1038 42.5.7 aes key word register x name: aes_keywrx [x=0..7] address: 0x40000020 access: write-only ? keyw: key word the four/six/eight 32-bit key word registers set the 128-bit/192-bit/256-bit cryptographic key used for aes encryption/decryption. aes_keywr0 corresponds to the first word of the key and re spectively aes_keywr3/ aes_keywr5/aes_keywr7 to the last one. whenever a new key (aes_keywrx) is written to the hardware two automatic actions are processed: ? gcm hash subkey generation ? aes_ghashrx clear (see section 42.4.5.2 for details.) these registers are write-only to prevent the key from being read by another application. 31 30 29 28 27 26 25 24 keyw 23 22 21 20 19 18 17 16 keyw 15 14 13 12 11 10 9 8 keyw 76543210 keyw
1039 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42.5.8 aes input data register x name: aes_idatarx [x=0..3] address: 0x40000040 access: write-only ? idata: input data word the four 32-bit input data regi sters set the 128-bit data block used for encryption/decryption. aes_idatar0 corresponds to the first word of the data to be encrypted/decrypted, and aes_idatar3 to the last one. these registers are write-only to prevent the input data from being read by another application. 31 30 29 28 27 26 25 24 idata 23 22 21 20 19 18 17 16 idata 15 14 13 12 11 10 9 8 idata 76543210 idata
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1040 42.5.9 aes output data register x name: aes_odatarx [x=0..3] address: 0x40000050 access: read-only ? odata: output data the four 32-bit output data registers contain the 128-bit data block that has been encrypted/decrypted. aes_odatar0 corresponds to the first word, aes_odatar3 to the last one. 31 30 29 28 27 26 25 24 odata 23 22 21 20 19 18 17 16 odata 15 14 13 12 11 10 9 8 odata 76543210 odata
1041 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42.5.10 aes initializati on vector register x name: aes_ivrx [x=0..3] address: 0x40000060 access: write-only ? iv: initialization vector the four 32-bit initialization vector registers set the 128-bit init ialization vector data block that is used by some modes of operation as an additional initial input. aes_ivr0 corresponds to the first word of the initialization vector, aes_ivr3 to the last one. these registers are write-only to prevent the initializ ation vector from being r ead by another application. for cbc, ofb and cfb modes, th e iv input value corresponds to the initialization vector. for ctr mode, the iv input value corr esponds to the init ial counter value. note: these registers are not used in ecb mode and must not be written. 31 30 29 28 27 26 25 24 iv 23 22 21 20 19 18 17 16 iv 15 14 13 12 11 10 9 8 iv 76543210 iv
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1042 42.5.11 aes additional authenticated data length register name: aes_aadlenr address: 0x40000070 access: read/write ? aadlen: additional authenticated data length length in bytes of the additional authenticated data ( aad ) that is to be processed. note: the maximum byte length of the aad portion of a message is limited to the 32-bit counter length. 31 30 29 28 27 26 25 24 aadlen 23 22 21 20 19 18 17 16 aadlen 15 14 13 12 11 10 9 8 aadlen 76543210 aadlen
1043 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42.5.12 aes plaintext/ciphertext length register name: aes_clenr address: 0x40000074 access: read/write ? clen: plaintext/ciphertext length length in bytes of the plaintext/ciphertext ( c ) data that is to be processed. note: the maximum byte length of the c portion of a message is limited to the 32-bit counter length. 31 30 29 28 27 26 25 24 clen 23 22 21 20 19 18 17 16 clen 15 14 13 12 11 10 9 8 clen 76543210 clen
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1044 42.5.13 aes gcm intermediate hash word register x name: aes_ghashrx [x=0..3] address: 0x40000078 access: read/write ? ghash: intermediate gcm hash word x the four 32-bit intermediate hash word registers expose the intermediate ghash value. may be read to save the current ghash value so processing can later be resumed, presumably on a later message fragment. whenever a new key (aes_keywrx) is written to the hardwa re two automatic ac tions are processed: ? gcm hash subkey generation ? aes_ghashrx clear (see section 42.4.5.2 for details.) if an application software s pecific hash initial va lue is needed for the gh ash it must be writ ten to the aes_ghashrx: ? after a write to aes_keywrx, if any ? prior to starting the input data feed 31 30 29 28 27 26 25 24 ghash 23 22 21 20 19 18 17 16 ghash 15 14 13 12 11 10 9 8 ghash 76543210 ghash
1045 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 42.5.14 aes gcm authentication tag word register x name: aes_tagrx [x=0..3] address: 0x40000088 access: read-only ? tag: gcm authentication tag x the four 32-bit tag registers contain th e final 128-bit gcm authentication tag ( t ) when gcm processing is complete. tag0 corresponds to the first word, tag3 to the last word. 42.5.15 aes gcm encryption counter value register name: aes_ctrr address: 0x40000098 access: read-only ? ctr: gcm encryption counter reports the current value of the 32-bit gcm counter. 31 30 29 28 27 26 25 24 tag 23 22 21 20 19 18 17 16 tag 15 14 13 12 11 10 9 8 tag 76543210 tag 31 30 29 28 27 26 25 24 ctr 23 22 21 20 19 18 17 16 ctr 15 14 13 12 11 10 9 8 ctr 76543210 ctr
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1046 42.5.16 aes gcm h word register x name: aes_gcmhrx [x=0..3] address: 0x4000009c access: read/write ? h: gcm h word x the four 32-bit h word registers contain the 128-bit gcm hash subkey h value. whenever a new key (aes_keywrx) is written to the hardware two automatic actions are processed: ? gcm hash subkey h generation ? aes_ghashrx clear if the application software requires a s pecific hash subkey, the automatically gener ated h value can be overwritten in the aes_gcmhrx (see section 42.4.5.2 for details). the choice of a gcm hash subkey h by a write in the aes_gcmhrx permits ? choosing the gcm hash subkey h for ghash operations ? choosing one operand to process a single gf128 multiply 31 30 29 28 27 26 25 24 h 23 22 21 20 19 18 17 16 h 15 14 13 12 11 10 9 8 h 76543210 h
1047 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43. integrity check monitor (icm) 43.1 description the integrity check monitor (icm) is a dma controller that performs hash calculation over multiple memory regions through the use of transfer descriptors located in memory (icm descriptor area). the hash function is based on the secure hash algorithm (sha). the icm contro ller integrates two modes of operation. the first one is used to hash a list of memory regions and save the dige sts to memory (icm hash area). the second operation mode is an active monitoring of the memory. in that mode, the hash function is evaluated and compared to the digest located at a predefined memory address (icm hash area). if a mismatch occurs, an interrupt is raised. see figure 43-1 for an example of four-region monitoring. hash and descriptor area s are located in memory instance i2, and the four regions are split in memory instances i0 and i1. the icm sha engine is comp liant with the american fips (federal information processing standard) publication 180-2 specification. the following terms are concise definitions of t he icm concepts used throughout this document: ? region?a partition of instruction or data memory space ? region descriptor?a data structure stor ed in memory, defining region attributes ? region attributes?region start address, region size, region sha engine processing mode, write back or compare function mode ? context registers?a set of icm non-memory-mapped, in ternal registers which are automatically loaded, containing the attributes of the region being processed ? main list?a list of region descriptors. each element associates the start address of a region with a set of attributes. ? secondary list?a linked list defined on a per region bas is that describes the memory layout of the region (when the region is non-contiguous) ? hash area?predefined memory space where the region hash results (digest) are stored figure 43-1. four-region monitoring example memory region 0 memory region 1 memory region 2 memory region 3 icm processor interrupt controller icm descriptor area icm hash area memory i0 memory i1 memory i2 system interconnect
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1048 43.2 embedded characteristics ? dma ahb master interface ? supports up to 4 non-contiguous memory region monitoring ? supports block gathering through the use of linked list ? supports secure hash algorithm (sha1, sha224, sha256) ? compliant with fips publication 180-2 ? configurable processing period: ? when sha1 algorithm is processed, the runt ime period is either 85 or 209 clock cycles. ? when sha256 or sha224 algorithm is processed, the runt ime period is either 72 or 194 clock cycles. ? programmable bus burden 43.3 block diagram figure 43-2. integrity check monitor block diagram integrity scheduler sha hash engine host interface context registers monitoring fsm configuration registers master dma interface apb bus layer
1049 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.4 product dependencies 43.4.1 power management the peripheral clock is not continuously provided to t he icm. the programmer must first enable the icm clock in the power management controller (pmc) before using the icm. 43.4.2 interrupt the icm interface has an interrupt line connected to the in terrupt controller. handling the icm interrupt requires programming the interrupt controller before configuring the icm. 43.5 functional description the integrity check monitor (icm) is a dma controller that performs sha-based memory hashing over memory regions. as shown in figure 43-2 , it integrates a dma interface, a monitoring finite state machine (fsm), an integrity scheduler, a set of contex t registers, a sha engine, an apb inte rface and co nfiguration registers. when the icm module is enabled, it sequentially retrieve s a circular list of region descriptors from the memory (main list described in figure 43-3 ). up to four regions may be monitored. each region descriptor is composed of four words indicating the layout of the memory region (see figure 43-4 ). it also contains the hashing engine configuration on a per region basis. as soon as the descriptor is loaded fr om the memory and context registers are updated with the data structure, the hashing operation starts. a programmable number of blocks (see trsize field of the icm_rctrl structure member) is transferred from the memory to the sha engine. when the desired number of blocks have been transferred, the digest is whether moved to memory (write back function) or compared with a digest reference locat ed in the system memory (compare func tion). if a digest mismatch occurs, an interrupt is triggered if unmasked. the icm module pa sses through the region descriptor list until the end of the list marked by an end of list bit set to one. to continuously monitor the list of regions, the wrap bit must be set to one in the last data structure. table 43-1. peripheral ids instance id icm 34
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1050 figure 43-3. icm region descriptor and hash areas each region descriptor supports gathering of data through the use of the secondary list. unlike the main list, the secondary list cannot modify the configuration attributes of the region. when the end of the secondary list has been encountered, the icm returns to the main list. memory integrity monitori ng can be considered as a background service and the mandatory bandwidth shall be very limited. in order to limit the icm memory bandwidth, use the bbc field of the icm_cfg register to control icm memory load. icm descriptor area - contiguous read-only memory region 0 descriptor region 1 descriptor region n descriptor wrap=1 wrap=0 wrap=0 infinite loop when wrap bit is set end of region 0 end of region 1 list end of region n region 0 hash region 1 hash region n hash icm hash area - contiguous read-write once memory main list secondary list
1051 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 43-4. region descriptor the icm integrates a secure hash algorithm engine (sha). this module requires a message padded according to fips180-2 specification. the sha module produces an n-bit message digest each time a block is read and a processing period ends. n is 160 for sha1, 224 for sha224, 256 for sha256. 43.5.1 icm region descriptor structure the icm region descriptor area is a contiguous area of system memory that the controller and the processor can access. when the icm controller is activated, the controlle r performs a descriptor fetch operation at *(icm_dscr) address. if the main list contains more than one descriptor (i.e., more than one region is to be monitored), the fetch address is *(icm_dscr) + (rid<<4) where rid is the region identifier. end of region 0 icmdscr region 0 descriptor region 1 descriptor region addr region cfg region ctrl region next 0x000 0x004 0x008 0x00c optional region 0 secondary list region addr unused region ctrl region next 0x000 0x004 0x008 0x00c region 2 descriptor region 3 descriptor main list table 43-2. region descriptor structure (main list) offset structure member name icm_dscr+0x000+rid*(0x10) icm region start address icm_raddr icm_dscr+0x004+rid*(0x10) icm re gion configuration icm_rcfg icm_dscr+0x008+rid*(0x10) icm region control icm_rctrl icm_dscr+0x00c+rid*(0x10) icm region next address icm_rnext
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1052 43.5.1.1 icm region start address structure member name: icm_raddr address : icm_dscr+0x000+rid*(0x10) access : read/write ? raddr: region start address this field indicates the first byte address of the region. 31 30 29 28 27 26 25 24 raddr 23 22 21 20 19 18 17 16 raddr 15 14 13 12 11 10 9 8 raddr 76543210 raddr
1053 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.5.1.2 icm region configuration structure member name: icm_rcfg address : icm_dscr+0x004+rid*(0x10) access : read/write ? cdwbn: compare digest or write back digest 0: the digest is written to the hash area. 1: the digest value is compared to the digest stored in the hash area. ? wrap: wrap command 0: the next region descriptor address loaded is the current region identifier descriptor address incremented by 0x10 1: the next region descriptor address loaded is icm_dscr. ? eom: end of monitoring 0: the current descriptor does not terminate the monitoring. 1: the current descriptor terminates the main list. wrap bit value has no effect. ? rhien: region hash completed interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? dmien: digest mismatch interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? beien: bus error interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? wcien: wrap condition interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. 31 30 29 28 27 26 25 24 ?? m r p r o t 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? algo ? procdly suien ecien 76543210 wcien beien dmien rhien ? eom wrap cdwbn
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1054 ? ecien: end bit condition interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? suien: monitoring status updated condition interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? procdly: processing delay when sha1 algorithm is processed, the runtim e period is either 85 or 209 clock cycles. when sha256 or sha224 algorithm is processed, the runtime period is either 72 or 194 clock cycles. ? algo: sha algorithm values which are not listed in the table must be considered as ?reserved?. ? mrprot: memory region ahb protection this field indicates the value of hprot ahb sign al when the icm retrie ves the memory region. value name description 0 shortest sha processing runt ime is the shortest one 1 longest sha processing runtime is the longest one value name description 0 sha1 sha1 algorithm processed 1 sha256 sha256 algorithm processed 4 sha224 sha224 algorithm processed
1055 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.5.1.3 icm region control structure member name: icm_rctrl address : icm_dscr+0x008+rid*(0x10) access: read/write ? trsize: transfer size for the current chunk of data icm performs a transfer of (t rsize+1) blocks of 512 bits. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 trsize 76543210 trsize
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1056 43.5.1.4 icm region next address structure member name: icm_rnext address : icm_dscr+0x00c+rid*(0x10) access: read/write ? next: region transfer descriptor next address when configured to 0, this field indicates that the current descr iptor is the last descriptor of the secondary list, otherwise it points at a new descriptor of the secondary list. 31 30 29 28 27 26 25 24 next 23 22 21 20 19 18 17 16 next 15 14 13 12 11 10 9 8 next 76543210 next ? ?
1057 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.5.2 icm hash area the icm hash area is a contiguous area of system memo ry that the controller and the processor can access. the physical location is configured in the icm hash area start address register. this address is a multiple of 128 bytes. if the cdwbn bit of the context register is cleared (i.e., write back activated), the ic m controller performs a digest write operation at the following starting location: *(icm_h ash) + (rid<<5), where rid is the current region context identifier. if the cdwbn bit of the context register is set (i.e., digest comparison ac tivated), the icm controller performs a digest read oper ation at the same address. 43.5.2.1 message digest example considering the following 512 bits message (example given in fips 180-2): ?61626380000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000018? the message is written to memory in a little endian (le) system architecture. the digest is stored at the memory location pointed at by the icm_hash point er with a region offset. table 43-3. 512 bits me ssage memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0 x 0 0 0 8 06 36 26 1 0x004?0x038 00 00 00 00 0 x 0 3 c 1 80 00 00 0 table 43-4. le resulting sha-160 message digest memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0 x 0 0 0 3 63 e9 9a 9 0 x 0 0 4 6 a8 10 64 7 0 x 0 0 8 7 12 53 eb a 0x00c 6c c2 50 78 0 x 0 1 0 9 dd 8d 09 c table 43-5. resulting sha-224 m essage digest memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0 x 0 0 0 2 27 d0 92 3 0 x 0 0 4 2 2d 80 53 4 0 x 0 0 8 7 7a 44 28 6 0 x 0 0 c b 35 5a 2b d 0x010 e4 bc ad 2a 0x014 f7 b3 a0 bd 0x018 a7 9d 6c e3
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1058 considering the following 1024 bits message (example given in fips 180-2): ?6162638000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000018? the message is written to memory in a little endian (le) system architecture. 43.5.3 icm sha engine the module can process sha1, sha224, sha256 by means of a configuratio n field in the sha_mr. 43.5.3.1 processing period the sha engine processing period can be configured. the short processing period allows to allocate bandwidth to the sha module whereas the long processing period allocates more bandwidth on the system bus to other applications. in sha mode, the shortest processi ng period is 85 clock cycles + 2 clock cycles for start command synchronization. the longest period is 209 clock cycles + 2 clock cycles. in sha256 and sha224 modes, the shortest processing period is 72 clock cycles + 2 clock cycles for start command synchronization. the longest period is 194 clock cycles + 2 clock cycles. 43.5.4 security features when an undefined register access occurs, the urad bit in the interrupt status register (icm_isr) is set if unmasked. its source is then report ed in the undefined access status register (icm_uasr). only the first undefined register access is available through the urat field. several kinds of unspecified register accesses can occur: table 43-6. resulting sha-256 m essage digest memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0x000 bf 16 78 ba 0x004 ea cf 01 8f 0 x 0 0 8 d e4 04 14 1 0 x 0 0 c 2 32 2a e5 d 0 x 0 1 0 a 36 10 3b 0 0x014 9c 7a 17 96 0x018 61 ff 10 b4 0 x 0 1 c a d1 50 0f 2 table 43-7. 1024 bits message memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0 x 0 0 0 8 06 36 26 1 0x004?0x078 00 00 00 00 0 x 0 7 c 1 80 00 00 0
1059 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? unspecified structure member set to one detected when the descriptor is loaded ? configuration register (icm_cfg) modified during active monitoring ? descriptor register (icm_dscr) mo dified during active monitoring ? hash register (icm_hash) modi fied during active monitoring ? write-only register read access the urad bit and the urat field can only be rese t by writing a 1 to the icm_ctrl.swrst bit. 43.5.5 icm automatic monitoring mode the ascd bit of the icm_cfg register is used to acti vate the icm automatic mode. when icm_cfg.ascd is set, the icm performs the following actions: ? the icm controller passes through the main list once wi th cdwbn bit in the context register at 0 (i.e., write back activated) and eom bit in context register at 0. ? when wrap = 1 in icm_rcfg, the icm controller ente rs active monitoring with cdwbn bit in context register now set and eom bit in context register cl eared. bits cdwbn and eom in the region descriptor structure member (icm_rcfg) have no effect.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1060 43.6 programming the icm for multiple regions table 43-8. region attributes transfer type main list icm_rcfg icm_rnext comments cdwbn wrap eom next single region contiguous list of blocks digest written to memory monitoring disabled 1 item 0 0 1 0 the main list contains only one descriptor. the secondary list is empty for that descriptor. the digest is computed and saved to memory. noncontiguous list of blocks digest written to memory monitoring disabled 1 item 0 0 1 secondary list address of the current region identifier the main list contains only one descriptor. the secondary list describes the layout of the non contiguous region. contiguous list of blocks digest comparison enabled monitoring enabled 1 item 1 1 0 0 when the hash computation is terminated, the digest is compared with the one saved in memory. multiple regions contiguous list of blocks digest written to memory monitoring disabled more than one item 00 1 for the last, 0 otherwise 0 icm passes through the list once. contiguous list of blocks digest comparison is enabled monitoring is enabled more than one item 1 1 for the last, 0 otherwise 00 icm performs active monitoring of the regions. if a mismatch occurs, an interrupt is raised. noncontiguous list of blocks digest is written to memory monitoring is disabled more than one item 001 secondary list address icm performs hashing and saves digests to the hash area. noncontiguous list of blocks digest comparison is enabled monitoring is enabled more than one item 110 secondary list address icm performs data gathering on a per region basis.
1061 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.7 integrity check monitor (icm) user interface table 43-9. register mapping offset register name access reset 0x00 configuration regi ster icm_cfg read/write 0x0 0x04 control register icm_ctrl write-only ? 0x08 status register icm_sr write-only ? 0x0c reserved ? ? ? 0x10 interrupt enable register icm_ier write-only ? 0x14 interrupt disable register icm_idr write-only ? 0x18 interrupt mask register icm_imr read-only 0x0 0x1c interrupt status register icm_isr read-only 0x0 0x20 undefined access status register icm_uasr read-only 0x0 0x24?0x2c reserved ? ? ? 0x30 region descriptor area start address register icm_dscr read/write 0x0 0x34 region hash area start address register icm_hash read/write 0x0 0x38 user initial hash value 0 register icm_uihval0 write-only ? ... ... ... ... ... 0x54 user initial hash value 7 icm_uihval7 write-only ? 0x58?0xfc reserved ? ??
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1062 43.7.1 icm configuration register name: icm_cfg address: 0x40044000 access: read/write ? wbdis: write back disable 0: write back operations are permitted. 1: write back operations are forbidden. context register cdwbn bit is internally set to one and cannot be modified by a linked list element. the cdwbn bit of the icm_rcfg structure member has no effect. when ascd bit of the icm_cfg register is set, wbdis bit value has no effect. ? eomdis: end of monitoring disable 0: end of monitoring is permitted 1: end of monitoring is forbidden. the eom bit of the icm_rcfg structure member has no effect. ? slbdis: secondary list branching disable 0: branching to the secondary list is permitted. 1: branching to the secondary list is fo rbidden. the next field of the icm_rnext structure member has no effect and is always considered as zero. ? bbc: bus burden control this field is used to control the burden of the icm system bus. the number of syst em clock cycles between the end of the current processing and the next block transfer is set to 2 bbc . up to 32,768 cycles can be inserted. ? ascd: automatic switch to compare digest 0: automatic mode is disabled. 1: when this mode is enabled, the icm controller automatically switches to active monitoring after the first main list pass. both cdwbn and wbdis bits have no effect. a one must be written to the eom bit in icm_rcfg to terminate the monitoring. ? dualbuff: dual input buffer 0: dual input buffer mode is disabled. 1: dual input buffer mode is enabled. 31 30 29 28 27 26 25 24 ? ? daprot 23 22 21 20 19 18 17 16 ? ? haprot 15 14 13 12 11 10 9 8 ualgo uihash ? ? dualbuff ascd 76543210 bbc ? slbdis eomdis wbdis
1063 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ? uihash: user initial hash value 0: the secure hash standard provides the initial hash value. 1: the initial hash value is programma ble. field ualgo provides the sha al gorithm. the algo field of the icm_rcfg structure member has no effect. ? ualgo: user sha algorithm ? daprot: region descri ptor area protection this field indicates the value of the bu s protection signals when the icm module performs a read operation in the region descriptor area. ? haprot: region hash area protection this field indicates the value of the bu s protection signals when the icm module performs a read operation in the region hash area. value name description 0 sha1 sha1 algorithm processed 1 sha256 sha256 algorithm processed 4 sha224 sha224 algorithm processed
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1064 43.7.2 icm control register name: icm_ctrl address: 0x40044004 access: write-only ? enable: icm enable 0: no effect 1: when set to one, the icm controller is activated. ? disable: icm disable register 0: no effect 1: the icm controller is disabled. if a regi on is active, this re gion is terminated. ? swrst: software reset 0: no effect. 1: resets the icm controller. ? rehash: recompute internal hash 0: no effect. 1: when rehash[ i ] is set to one, region i digest is re-computed. this bit is only available when region monitoring is disabled. ? rmdis: region monitoring disable 0: no effect 1: when bit rmdis[ i ] is set to one, the monitori ng of region with identifier i is disabled. ? rmen: region monitoring enable 0: no effect 1: when bit rmen[ i ] is set to one, the monitori ng of region with identifier i is activated. monitoring is activated by default. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rmen rmdis 76543210 rehash ? swrst disable enable
1065 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.7.3 icm status register name: icm_sr address: 0x40044008 access: read-only ? enable: icm controller enable register 0: icm controller is disabled. 1: icm controller is activated. ? rawrmdis: raw region m onitoring disabled status 0: raw region monitoring is activated 1: raw region monitoring is deactivated ? rmdis: region monitoring disabled status 0: region monitoring is activated 1: region monitoring is deactivated 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rmdis rawrmdis 76543210 ???????e n a b l e
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1066 43.7.4 icm interrupt enable register name: icm_ier address: 0x40044010 access: write-only ? rhc: region hash completed interrupt enable 0: no effect 1: when rhc[ i ] is set to one, the region i hash completed in terrupt is enabled. ? rdm: region digest mismatch interrupt enable 0: no effect 1: when rdm[ i ] is set to one, the region i digest mismatch interrupt is enabled. ? rbe: region bus er ror interrupt enable 0: no effect. 1: when rbe[ i ] is set to one, the region i bus error interrupt is enabled. ? rwc: region wrap condition detected interrupt enable 0: no effect. 1: when rwc[ i ] is set to one, the region i wrap condition interrupt is enabled. ? rec: region end bit condition detected interrupt enable 0: no effect. 1: when rec[ i ] is set to one, the region i end bit condition interrupt is enabled. ? rsu: region status updated interrupt disable 0: no effect. 1: when rsu[ i ] is set to one, the region i status updated interrupt is enabled. ? urad: undefined register access detection interrupt enable 0: no effect. 1: the undefined register access interrupt is enabled. 31 30 29 28 27 26 25 24 ???????u r a d 23 22 21 20 19 18 17 16 rsu rec 15 14 13 12 11 10 9 8 rwc rbe 76543210 rdm rhc
1067 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.7.5 icm interrupt disable register name: icm_idr address: 0x40044014 access: write-only ? rhc: region hash completed interrupt disable 0: no effect 1: when rhc[ i ] is set to one, the region i hash completed interrupt is disabled. ? rdm: region digest mismatch interrupt disable 0: no effect 1: when rdm[ i ] is set to one, the region i digest mismatch interrupt is disabled. ? rbe: region bus erro r interrupt disable 0: no effect. 1: when rbe[ i ] is set to one, the region i bus error interrupt is disabled. ? rwc: region wrap condition detected interrupt disable 0: no effect. 1: when rwc[ i ] is set to one, the region i wrap condition interrupt is disabled. ? rec: region end bit condition detected interrupt disable 0: no effect. 1: when rec[ i ] is set to one, the region i end bit condition interrupt is disabled. ? rsu: region status updated interrupt disable 0: no effect. 1: when rsu[ i ] is set to one, the region i status updated interrupt is disabled. ? urad: undefined register access detection interrupt disable 0: no effect. 1: undefined register access dete ction interrupt is disabled. 31 30 29 28 27 26 25 24 ???????u r a d 23 22 21 20 19 18 17 16 rsu rec 15 14 13 12 11 10 9 8 rwc rbe 76543210 rdm rhc
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1068 43.7.6 icm interrupt mask register name: icm_imr address: 0x40044018 access: read-only ? rhc: region hash completed interrupt mask 0: when rhc[i] is set to zero, the interrupt is disabled for region i. 1: when rhc[i] is set to one, the interrupt is enabled for region i. ? rdm: region digest mismatch interrupt mask 0: when rdm[i] is set to zero, the in terrupt is disabled for region i. 1: when rdm[i] is set to one, the interrupt is enabled for region i. ? rbe: region bus er ror interrupt mask 0: when rbe[i] is set to zero, the interrupt is disabled for region i. 1: when rbe[i] is set to one, the interrupt is enabled for region i. ? rwc: region wrap condition detected interrupt mask 0: when rwc[i] is set to zero, th e interrupt is disabled for region i. 1: when rwc[i] is set to one, the interrupt is enabled for region i. ? rec: region end bit condition detected interrupt mask 0: when rec[i] is set to zero, the interrupt is disa bled for region i. 1: when rec[i] is set to one, the interrupt is enabled for region i. ? rsu: region status updated interrupt mask 0: when rsu[i] is set to zero, the interrupt is disa bled for region i. 1: when rsu[i] is set to one, the interrupt is enabled for region i. ? urad: undefined register access detection interrupt mask 0: interrupt is disabled 1: interrupt is enabled. 31 30 29 28 27 26 25 24 ???????u r a d 23 22 21 20 19 18 17 16 rsu rec 15 14 13 12 11 10 9 8 rwc rbe 76543210 rdm rhc
1069 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.7.7 icm interrupt status register name: icm_isr address: 0x4004401c access: read-only ? rhc: region hash completed when rhc[ i ] is set, it indicates that the icm ha s completed the region with identifier i . ? rdm: region digest mismatch when rdm[ i ] is set, it indicates that there is a digest comparison mismatch between the hash value of the region with iden- tifier i and the reference value located in the hash area. ? rbe: region bus error when rbe[ i ] is set, it indicates that a bus error has been detected while hashing memory region i . ? rwc: region wrap condition detected when rwc[ i ] is set, it indicates that a wrap condition has been detected. ? rec: region end bit condition detected when rec[ i ] is set, it indicates that an end bit condition has been detected. ? rsu: region status updated detected when rsu[ i ] is set, it indicates that a region status updated condition has been detected. ? urad: undefined register access detection status 0: no undefined register access ha s been detected since the last swrst. 1: at least one undefined register access has been detected since the last swrst. the urad bit is only reset by the sw rst bit in the icm_ctrl register. the urat field in the icm_uasr indi cates the unspecified access type. 31 30 29 28 27 26 25 24 ???????u r a d 23 22 21 20 19 18 17 16 rsu rec 15 14 13 12 11 10 9 8 rwc rbe 76543210 rdm rhc
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1070 43.7.8 icm undefined access status register name: icm_uasr address: 0x40044020 access: read-only ? urat: undefined register access trace only the first undefined register access trace is available through the urat field. the urat field is only reset by the swrst bit in the icm_ctrl register. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????? u r a t value name description 0 unspec_struct_member unspecified structure member se t to one detected when the descriptor is loaded. 1 icm_cfg_modified icm_cfg modified during active monitoring. 2 icm_dscr_modified icm_dscr modifi ed during active monitoring. 3 icm_hash_modified icm_hash modified during active monitoring 4 read_access write-only register read access
1071 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.7.9 icm descriptor area start address register name: icm_dscr address: 0x40044030 access: read/write ? dasa: descriptor area start address the start address is a multiple of the tota l size of the data structure (64 bytes). 31 30 29 28 27 26 25 24 dasa 23 22 21 20 19 18 17 16 dasa 15 14 13 12 11 10 9 8 dasa 76543210 d a s a ??????
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1072 43.7.10 icm hash area start address register name: icm_hash address: 0x40044034 access: read/write ? hasa: hash area start address this field points at the hash memory location. the address must be a multiple of 128 bytes. 31 30 29 28 27 26 25 24 hasa 23 22 21 20 19 18 17 16 hasa 15 14 13 12 11 10 9 8 hasa 76543210 h a s a???????
1073 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 43.7.11 icm user initial hash value register name: icm_uihvalx [x=0..7] address: 0x40044038 access: write-only ? val: initial hash value when uihash bit of imc_cfg register is set, the initial hash value is user-programmable. to meet the desired standard, use the following example values. for icm_uihval0 field: for icm_uihval1 field: for icm_uihval2 field: for icm_uihval3 field: 31 30 29 28 27 26 25 24 val 23 22 21 20 19 18 17 16 val 15 14 13 12 11 10 9 8 val 76543210 val example comment 0x67452301 sha1 algorithm 0xc1059ed8 sha224 algorithm 0x6a09e667 sha256 algorithm example comment 0xefcdab89 sha1 algorithm 0x367cd507 sha224 algorithm 0xbb67ae85 sha256 algorithm example comment 0x98badcfe sha1 algorithm 0x3070dd17 sha224 algorithm 0x3c6ef372 sha256 algorithm example comment 0x10325476 sha1 algorithm 0xf70e5939 sha224 algorithm 0xa54ff53a sha256 algorithm
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1074 for icm_uihval4 field: for icm_uihval5 field: for icm_uihval6 field: for icm_uihval7 field: example of initial valu e for sha-1 algorithm example comment 0xc3d2e1f0 sha1 algorithm 0xffc00b31 sha224 algorithm 0x510e527f sha256 algorithm example comment 0x68581511 sha224 algorithm 0x9b05688c sha256 algorithm example comment 0x64f98fa7 sha224 algorithm 0x1f83d9ab sha256 algorithm example comment 0xbefa4fa4 sha224 algorithm 0x5be0cd19 sha256 algorithm register address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0x000 icm_uihval0 01 23 45 67 0x004 icm_uihval1 89 ab cd ef 0x008 icm_uihval2 fe dc ba 98 0x00c icm_uihval3 76 54 32 10 0x010 icm_uihval4 f0 e1 d2 c3
1075 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 44. classical public key crypto graphy controller (cpkcc) 44.1 description the classical public key cryptography controller (cpkcc) is an atmel macrocell that processes public key cryptography algorithm calculus in both gf(p) and gf(2^n ) fields. the romed cpkcl, the classical public key cryptography library, is the library built on the top of the cpkcc. the classical public key cryptography library includes complete implementation of the following public key cryptography algorithms: ? rsa, dsa: ? modular exponentiation with crt up to 6144 bits ? modular exponentiation without crt up to 5408 bits ? prime generation ? utilities: gcd/modular inverse, divi de, modular reducti on, multiply, ? ? elliptic curves: ? ecdsa up to 1504 bits ? point multiply, ? point add/doubling ? elliptic curves in gf(p) or gf(2^n) ? choice of the curves parameters so compatibility with nist curves or others. ? deterministic random number generation (drng ansi x9.31) for dsa
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1076 44.2 product dependencies 44.2.1 power management the cpkcc is not continuously cl ocked. the cpckcc interface is clocked through the power management controller (pmc). 44.2.2 interrupt sources the cpkcc has an interrupt line connected to the nested vector interrupt controller (nvic). handling interrupts requires programming the nvic before configuring the cpkcc. 44.3 functional description the cpkcc macrocell is managed by the cpkcl library available in the rom memory of the sam4c. the user interface of the cpkcc is not described in this chapter. the usage description of the cpkcc and its associated library is provided in a separate document. contact an atmel sales representative for further details.
1077 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 45. true random number generator (trng) 45.1 description the true random number generator (trng) passes the american nist special publicat ion 800-22 and diehard random tests suites. the trng may be used as an entropy source for seeding an nist approved drng (deterministic rng) as required by fips pub 140-2 and 140-3. 45.2 embedded characteristics ? passed nist special pub lication 800-22 tests suite ? passed diehard random tests suite ? may be used as entropy source for seeding an nist approved drng (deterministic rng) as required by fips pub 140-2 and 140-3 ? provides a 32-bit random number every 84 clock cycles 45.3 block diagram figure 45-1. trng block diagram user interf ace apb interr upt controller pmc entropy source mck trng control logic
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1078 45.4 product dependencies 45.4.1 power management the trng interface may be clocked through the power management controller (pmc), thus the programmer must first configure the pmc to enable the trng user interface clock. the user interface clock is independent from any clock that may be used in the entropy source logic circuitry. the so urce of entropy can be enabled before enabling the user interface clock. 45.4.2 interrupt the trng interface has an interrupt line connected to the interrupt controller. in order to handle interrupts, the interrupt controller must be programmed before configuring the trng. 45.5 functional description as soon as the trng is enabled in the control register (trng_cr), the generator provides one 32-bit value every 84 clock cycles. interrupt trng_int can be enabled in the trng_ier (respect ively disabled in the trng_idr). this interrupt is set when a new random value is available and is cleared when the status register (trng_isr) is read. the flag datrdy of the (trng_isr) is set when the r andom data is ready to be read out on the 32-bit output data register (trng_odata). the normal mode of operation checks that the status register flag equals 1 be fore reading the output data register when a 32-bit random value is required by the software application. figure 45-2. trng data generation sequence table 45-1. peripheral ids instance id trng 33 84 clock cycles 84 clock cycles 84 clock cycles read trng_isr read trng_odata read trng_isr read trng_odata clock trng_int trng_cr enable
1079 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 45.6 true random number gene rator (trng) user interface table 45-2. register mapping offset register name access reset 0x00 control register trng_cr write-only ? 0x10 interrupt enable regi ster trng_ier write-only ? 0x14 interrupt disable register trng_idr write-only ? 0x18 interrupt mask register trng_imr read-only 0x0000_0000 0x1c interrupt status r egister trng_isr read-only 0x0000_0000 0x50 output data regist er trng_odata read-only 0x0000_0000 0xfc reserved ?? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1080 45.6.1 trng control register name: trng_cr address: 0x40048000 access: write-only ? enable: enables the trng to provide random values 0: disables the trng. 1: enables the trng if 0x524e 47 (?rng? in ascii) is written in key field at the same time. ? key: security key. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 key 15 14 13 12 11 10 9 8 key 76543210 ???????e n a b l e value name description 0x524e47 passwd writing any other value in this field aborts the write operation.
1081 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 45.6.2 trng interrupt enable register name: trng_ier address: 0x40048010 access: write-only ? datrdy: data ready interrupt enable 0: no effect. 1: enables the corresponding interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????d a t r d y
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1082 45.6.3 trng interrupt disable register name: trng_idr address: 0x40048014 access: write-only ? datrdy: data ready interrupt disable 0: no effect. 1: disables the corresponding interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????d a t r d y
1083 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 45.6.4 trng interrupt mask register name: trng_imr address: 0x40048018 reset: 0x0000_0000 ? datrdy: data ready interrupt mask 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????d a t r d y
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1084 45.6.5 trng interrupt status register name: trng_isr address: 0x4004801c reset: 0x0000_0000 ? datrdy: data ready 0: output data is not va lid or trng is disabled. 1: new random value is completed. datrdy is cleared when this register is read. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?????? 76543210 ???????d a t r d y
1085 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 45.6.6 trng output data register name: trng_odata address: 0x40048050 reset: 0x0000_0000 ? odata: output data the 32-bit output data register contains the 32-bit random data. 31 30 29 28 27 26 25 24 odata 23 22 21 20 19 18 17 16 odata 15 14 13 12 11 10 9 8 odata 76543210 odata
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1086 46. electrical characteristics 46.1 absolute maximum ratings table 46-1. absolute maximum ratings* storage temperature......................................-60c to + 150c *notice: stresses beyond those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at these or other conditions beyond those indi- cated in the operational sectio ns of this specification is not implied. exposure to absolute maximum rating conditions for extended periods may affect device reliability. voltage difference between two ground pins (among gnd, gnda and gndref)... .............. .............50mv power supply inputs with respect to ground pins: vddcore, vddpll..........................................................1.4v vddbu, vddio, vddin, vddlcd, vddin_afe..............4.0v voltage on digital input pins with respect to ground .............. ...........-0.3v to vddio +0.3v voltage on analog input pins vpx, vnx with respect to ground............... ............-0.3v to vdda + 0.3v voltage on analog input pins ipx, inx with respect to ground............... ...............-2v to vdda + 0.3v total dc output current on all i/o lines 100-lead lqfp............. .......................................... ........100 ma
1087 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.2 recommended op erating conditions table 46-2. recommended operating conditions on power supply inputs symbol parameter conditions min typ max unit vddcore core logic power supply ? 1.08 1.20 1.32 v vddbu backup region power supply ? 1.62 3.3 3.6 v vddio i/os power supply ? 1.62 3.3 3.6 v vddin analog cells (voltage regulators, 10-bit adc, temperature sensor) power supply ? 1.62 3.3 3.6 v vddlcd lcd output buffers power supply ? 2.4 ? 3.6 v vddpll plls and main crystal oscillator power supply ? 1.08 ? 1.32 v vddin_afe vdda regulator power supply ? 3.0 3.3 3.6 v vdda emafe analog circuits power supply input ? 2.7 2.8 2.9 v f mck master clock frequency vddcore @ 1.20v, t a = 85c vddcore @ 1.08v, t a = 85c ?? 120 100 mhz table 46-3. recommended operating conditions on input pins symbol parameter conditions min typ max unit ad[x] in input voltage range on 10-bit adc analog inputs on ad[0..x] 0 ? min (vddin, vddio) v emafe in input voltage range on emafe input pins on i p{0,1,2,3} , i n{0,1,2,3} and v p{1,2,3} -0.25 ? 0.25 v v gpio_in input voltage range on gpios on any pin configured as a digital input 0 ? vddio v table 46-4. recommended thermal operating conditions symbol parameter conditions min typ max unit t a ambient temperature range ? -40 ? +85 c t j junction temperature range ? -40 ? 100 r ja junction-to-ambient thermal resistance lqfp100 (sam4cm16/8) ? 43 ? c/w lqfp100 (sam4cm32) ? 41 ? p d power dissipation lqfp100 (sam4cm16/8) t a = 70c ? ? 700 mw t a = 85c ? ? 350 lqfp100 (sam4cm32) t a = 70c ? ? 730 t a = 85c ? ? 365
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1088 46.3 electrical pa rameters usage the tables that follow further on in section 46.4 ?i/o characteristics? , section 46.5 ?embedded analog peripherals characteristics? , section 46.6 ?embedded flash characteristics? , and section 46.7 ?power supply current consumption? define the limiting values for several electrical parameters. unless other wise noted, these values are valid over the ambient temperature range t a = [-40c + 85c]. note that these limits may be affected by the board on which the mcu is mounted. particularly, noi sy supply and ground conditions must be avoided and care must be taken to provide: ? a pcb with a low impedance ground plane (unbroken ground planes are strongly recommended) ? low impedance decoupling of the mcu power supply inputs. a 100 nf ceramic x7r (or x5r) capacitor placed very close to each power supply input is a minimum requirement. see special recommendations regarding integrated analog functions like voltage refere nce or voltage regulators in corresponding sections. ? low impedance power supply decoupling of external co mponents. this recommendation aims at avoiding current spikes travelling in to the pcb ground plane.
1089 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.4 i/o characteristics 46.4.1 i/o dc characteristics table 46-5. i/o dc characteristics symbol parameter conditions min typ max unit v il low-level input voltage 1.62v < v ddio < 3.6v ? ? 0.3 x v vddio v v ih high-level input voltage 1.62v < v ddio < 3.6v 0.7 x v ddio ??v v oh high-level output voltage 1.62v < v ddio < 3.6v i oh = 0 i oh > 0 (see i oh details below) v ddio v ddio - 0.4 ? ? v v ol low-level output voltage 1.62v < v ddio < 3.6v i ol = 0 i ol > 0 (see iol details below) ?? 0 0.4 v i oh high-level output current pa0, pa8, pa29, pb13, pc0, pc5 pins (1) ?? ? ma v ddio = 1.62v; v oh = v ddio - 0.4 v ddio = 3.3v; v oh = v ddio - 0.4 v ddio = 3.6v; v oh = v ddio - 0.4 ?? -7 -7 -11 other gpio pins, low drive (2) ?? v ddio = 1.62v; v oh = v ddio - 0.4 v ddio = 3.3v; v oh = v ddio - 0.4 v ddio = 3.6v; v oh = v ddio - 0.4 ?? -3 -5 -6 other gpio pins, high drive (2) ?? ? v ddio = 1.62v; v oh = v ddio - 0.4 v ddio = 3.3v; v oh = v ddio - 0.4 v ddio = 3.6v; v oh = v ddio - 0.4 ?? -6 -8 -8 relaxed mode (3) pa0, pa8, pa29, pb13, pc0, pc5 pins ?? ? v ddio = 1.62v; v oh = v ddio - 0.6 v ddio = 3.3v; v oh = 2.2v v ddio = 3.6v; v oh = 2.4v ?? -12 -22 -26 relaxed mode (3) other gpio pins, low drive (2) ?? ? v ddio = 1.62v; v oh = v ddio - 0.6 v ddio = 3.3v; v oh = 2.2v v ddio = 3.6v; v oh = 2.4v ?? -5 -12 -13 relaxed mode (3) other gpio pins, high drive (2) ?? ? v ddio = 1.62v; v oh = v ddio - 0.6 v ddio = 3.3v; v oh = 2.2v v ddio = 3.6v; v oh = 2.4v ?? -10 -20 -24
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1090 notes: 1. these i/o lines have permanent non-programmable maximum drive (maxdrv) 2. refer to ?peripheral signal multiplexing on i/o lines? tables in the section ?peripherals?. 3. relaxed mode applies for cases of higher output current on the i/o lines that override standard v ol and v oh definitions. i ol low-level output current 1.62v < v vddio < 3.6v; v ol = 0.4v ? ? ? ma pa0, pa8, pa29, pb13, pc0, pc5 pins (1) other gpio pins, low drive (2) other gpio pins, high drive (2) ?? 9 8 10 relaxed mode (3) 1.62v < v vddio < 3.6v; v ol = 0.6v ?? ? pa0, pa8, pa29,p b13, pc0, pc5 pins (1) other gpio pins, low drive (2) other gpio pins, high drive (2) ?? 13 10 13 v hyst hysteresis voltage hysteresis mode enabled 150 ? ? mv i il input low leakage current no pull-up or pull-down; v in =gnd; v ddio max. (typ: t a = 25c, max: t a = 85c) - pa0, pa8, pa29, pb13, pc0, pc5 pins - pb16, pb17, pb18, pb19, pb20, pb21 pins - other pins ? 12 5 4 57 41 7 na i ih input high leakage current no pull-up or pull-down; v in =vdd; v ddio max. (typ: t a = 25c, max: t a = 85c) - pa0, pa8, pa29, pb13, pc0, pc5 pins - pb16, pb17, pb18, pb19, pb20, pb21 pins - other pins ? 15 1.7 5 150 9 14 na r pullup pull-up resistor digital input mode 70 100 130 k r pulldown pull-down resistor 70 100 130 k r odt on-die series termination resistor ?36 ? c pad input capacitance i/o configured as digital input ? ? 5 pf table 46-5. i/o dc characteristics (continued) symbol parameter conditions min typ max unit
1091 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.4.2 i/o ac characteristics criteria used to define the maximum frequency of the i/os: ? output duty cycle (40%-60%) ? minimum output swing: 100 mv to vddio - 100 mv ? minimum output swing: 100 mv to vddio - 100 mv ? addition of rising and falling time inferior to 75% of the period notes: 1. pin group 1 = pa0, pa8, pa29, pb13, pc0, pc5 pins 2. other pins, low drive settings 3. other pins, medium drive settings table 46-7 provides the input characteristics of the i/o lines. in particular, thes e values apply when the xin input is used as a clock input of the device (oscillator set in by pass mode). they do not apply for the xin32 input which is made for slow signals with frequencies up to 50 khz. vil and vih parameters defined in table 46-5 on page 1089 apply. table 46-6. output ac characteristics symbol parameter conditions min max unit freqmax1 pin group 1 (1) maximum output frequency 10 pf v ddio = 3.3v ?70 mhz 30 pf ? 45 freqmax2 pin group 2 (2) maximum output frequency 10 pf v ddio = 3.3v ?35 mhz 25 pf ? 15 freqmax3 pin group 3 (3) maximum output frequency 10 pf v ddio = 3.3v ?70 mhz 25 pf ? 35 table 46-7. input characteristics symbol parameter conditions min typ max units f in input frequency ? ? 50 mhz t in input period 20 ? ? ns t high time at high level 8 ? ? ns t low time at low level 8 ? ? ns t r rise time ? ? 2.2 ns t f fall time ? ? 2.2 ns t in t low t high t high t r t f v il v ih
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1092 46.4.3 spi characteristics figure 46-1. spi master mode with (cpol= ncpha = 0) or (cpol= ncpha= 1) figure 46-2. spi master mode with (cpol = 0 and ncpha=1) or (c pol=1 and ncpha= 0) figure 46-3. spi slave mode with (cpol=0 and ncpha=1) or (cpol=1 and ncpha=0) spck miso mosi spi 2 spi 0 spi 1 spck miso mosi spi 5 spi 3 spi 4 spck miso mosi spi 6 spi 7 spi 8 npcss spi 12 spi 13
1093 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-4. spi slave mode with (cpol = ncpha = 0) or (cpol= ncpha= 1) spck miso mosi spi 9 spi 10 spi 11 npcs0 spi 14 spi 15
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1094 46.4.3.1 maximum spi frequency the formulas that follow give maximum spi frequency in master write and read modes and in slave read and write modes. master write mode the spi is only sending data to a slave device such as an lcd, for example. the limit is given by spi 2 (or spi 5 ) timing. since it gives a maximum frequency above the maximum pad speed (see section 46.4.2 ?i/o ac characteristics? ), the max spi frequency is the one from the pad. master read mode t valid is the slave time response to ou tput data after detecting an spck edge. for atmel spi dataflash (at45db642d), t valid (or t v ) is 12 ns max. in the formula above, f spck max = 40 mhz @ vddio = 3.3v. slave read mode in slave mode, spck is the input cloc k for the spi. the max spck frequenc y is given by se tup and hold timings spi 7 /spi 8 (or spi 10 /spi 11 ). since this gives a frequency well above the pad limit, the limit in slave read mode is given by spck pad. slave write mode t setup is the setup time from the master before sampling data. f spck max 1 spi 0 orspi 3 () t valid + ------------------------------------------------------ = f spck max 1 2 xs ( pi 6 max orspi 9 max () t setup ) + ------------------------------------------------------------------------------------ - =
1095 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.4.3.2 spi timings notes: 1. 3.3v domain: v vddio from 2.85 v to 3.6v, maximum external capacitor = 10 pf. 2. 1.8v domain: v vddio from 1.65v to 1.95v, maximum external capacitor = 10 pf. note that in spi master mode, the device does not sample the data (miso) on the opposite edge where data clocks out (mosi) but the same edge is used as shown in figure 46-1 and figure 46-2 . table 46-8. spi timings symbol parameter conditions (1)(2) min max unit spi 0 miso setup time before spck rises (master) 3.3v domain 15.3 ? ns 1.8v domain 17.3 ? ns spi 1 miso hold time afte r spck rises (master) 3.3v domain -3.9 ? ns 1.8v domain -4.6 ? ns spi 2 spck rising to mosi delay (master) 3.3v domain -5.5 1.5 ns 1.8v domain -5.5 1.5 ns spi 3 miso setup time before spck falls (master) 3.3v domain 21.7 ? ns 1.8v domain 22.4 ? ns spi 4 miso hold time after spck falls (master) 3.3v domain -8.1 ? ns 1.8v domain -8.9 ? ns spi 5 spck falling to mosi delay (master) 3.3v domain -9.9 -4.2 ns 1.8v domain -9.9 -4.2 ns spi 6 spck falling to miso delay (slave) 3.3v domain 3.9 13.8 ns 1.8v domain 4.5 15.1 ns spi 7 mosi setup time before spck rises (slave) 3.3v domain 0.4 ? ns 1.8v domain 1.2 ? ns spi 8 mosi hold time after spck rises (slave) 3.3v domain 3.9 ? ns 1.8v domain 3.9 ? ns spi 9 spck rising to miso delay (slave) 3.3v domain 4.0 14.4 ns 1.8v domain 4.4 15.2 ns spi 10 mosi setup time before spck falls (slave) 3.3v domain 1.1 ? ns 1.8v domain 1.2 ? ns spi 11 mosi hold time after spck falls (slave) 3.3v domain 2.8 ? ns 1.8v domain 2.8 ? ns spi 12 npcs setup to spck rising (slave) 3.3v domain 3.8 ? ns 1.8v domain 3.8 ? ns spi 13 npcs hold after spck falling (slave) 3.3v domain -29.9 ? ns 1.8v domain -29.9 ? ns spi 14 npcs setup to spc k falling (slave) 3.3v domain 4.5 ? ns 1.8v domain 4.2 ? ns spi 15 npcs hold after spck falling (slave) 3.3v domain -28.7 ? ns 1.8v domain -28.7 ? ns
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1096 46.4.4 smc timings timings are given in the following domains: ? 1.8v domain: vddio from 1.65v to 1.95v, maximum external capacitor = 10 pf ? 3.3v domain: vddio from 2.85v to 3.6v , maximum external capacitor = 10 pf timings are given assuming a capacitance load on data, control and address pads. in tables that follow, t cpmck is mck period. 46.4.4.1 read timings notes: 1. 1.8v domain: vddio from 1.65v to 1.95v, maximum external capacitor = 10 pf. 2. 3.3v domain: vddio from 3.0v to 3.6v, maximum external capacitor = 10 pf. notes: 1. 1.8v domain: vddio from 1.65v to 1.95v, maximum external capacitor = 10 pf. 2. 3.3v domain: vddio from 3.0v to 3.6v, maximum external capacitor = 10 pf. table 46-9. smc read signals - nrd controlled (read_mode = 1) symbol paramete rminmaxunit vddio supply 1.8v (1) 3.3v (2) no hold settings (nrd hold = 0) smc 1 data setup before nrd high 18 18 ? ? ns smc 2 data hold after nrd high -6.7 -6.7 ? ? ns hold settings (nrd hold 0) smc 3 data setup before nrd high 11.7 11.7 ? ? ns smc 4 data hold after nrd high -6.5 -6.5 ? ? ns hold or no hold settings (nrd hold 0, nrd hold = 0) smc 5 nbs0/a0, nbs1, a1 - a23 valid before nrd high (nrd setup + nrd pulse) * t cpmck - 5.2 (nrd setup + nrd pulse) * t cpmck - 5.2 ??ns smc 6 ncs low before nrd high (nrd setup + nrd pulse - ncs rd setup) * t cpmck - 1.1 (nrd setup + nrd pulse - ncs rd setup) * t cpmck - 1.1 ??ns smc 7 nrd pulse width nrd pulse * t cpmck - 3.2 nrd pulse * t cpmck - 3.2 ? ? ns table 46-10. smc read signals - ncs controlled (read_mode= 0) symbol parameter min max unit vddio supply 1.8v (1) 3.3v (2) no hold settings (ncs rd hold = 0) smc 8 data setup before ncs high 31.3 31.3 ? ? ns smc 9 data hold after ncs high -6.9 -6.9 ? ? ns hold settings (ncs rd hold 0) smc 10 data setup before ncs high 23 23 ? ? ns smc 11 data hold after ncs high -6.6 -6.6 ? ? ns hold or no hold settings (ncs rd hold 0, ncs rd hold = 0) smc 12 nbs0/a0, nbs1, a1?a23 valid before ncs high (ncs rd setup + ncs rd pulse)* t cpmck - 4.9 (ncs rd setup + ncs rd pulse)* t cpmck - 4.9 ??ns smc 13 nrd low before ncs high (ncs rd setup + ncs rd pulse - nrd setup)* t cpmck - 1.5 (ncs rd setup + ncs rd pulse - nrd setup)* t cpmck - 1.5 ??n s smc 14 ncs pulse width ncs rd pulse length * t cpmck - 5.4 ncs rd pulse length * t cpmck - 5.4 ??ns
1097 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.4.4.2 write timings notes: 1. 1.8v domain: vddio from 1.65v to 1.95v, maximum external capacitor = 10 pf. 2. 3.3v domain: vddio from 3.0v to 3.6v, maximum external capacitor = 10 pf. 3. hold length = total cycle duration - setup duration - pulse durati on. ?hold length? is for ?ncs wr hold length? or ?nwe hold length?. notes: 1. 1.8v domain: vddio from 1.65v to 1.95v, maximum external capacitor = 10 pf. 2. 3.3v domain: vddio from 3.0v to 3.6v, maximum external capacitor = 10 pf. table 46-11. smc write signals - nwe controlled (write_mode = 1) symbol parameter min max unit 1.8v (1) 3.3v (2) hold or no hold settings (nwe hold 0, nwe hold = 0) smc 15 data out valid before nwe high nwe pulse * t cpmck - 2.6 nwe pulse * t cpmck - 2.6 ??ns smc 16 nwe pulse width nwe pulse * t cpmck + 10.8 nwe pulse * t cpmck + 10.8 ??ns smc 17 nbs0/a0 nbs1, a1 - a23 valid before nwe low nwe setup * t cpmck - 5.6 nwe setup * t cpmck - 5.6 ??ns smc 18 ncs low before nwe high (nwe setup - ncs rd setup + nwe pulse) * t cpmck - 0.5 (nwe setup - ncs rd setup + nwe pulse) * t cpmck - 0.5 ??ns hold settings (nwe hold 0) smc 19 nwe high to data out, nbs0/a0 nbs1, a1 - a23 change nwe hold * t cpmck - 4.2 nwe hold * t cpmck - 4.2 ??ns smc 20 nwe high to ncs inactive (1) (nwe hold - ncs wr hold)* t cpmck - 2.5 (nwe hold - ncs wr hold)* t cpmck - 2.5 ??ns no hold settings (nwe hold = 0) smc 21 nwe high to data out, nbs0/a0 nbs1, a1 - a23, ncs change (3) 5.4 5.4 ? ? ns table 46-12. smc write ncs controlled (write_mode = 0) symbol parameter min max units 1.8v (1) 3.3v (2) smc 22 data out valid before ncs high ncs wr pulse * t cpmck - 3.9 ncs wr pulse * t cpmck - 3.9 ??ns smc 23 ncs pulse width ncs wr pulse * t cpmck - 3.1 ncs wr pulse * t cpmck - 3.1 ??ns smc 24 nbs0/a0 nbs1, a1 - a23 valid before ncs low ncs wr setup * t cpmck - 5.1 ncs wr setup * t cpmck - 5.1 ??ns smc 25 nwe low before ncs high (ncs wr setup - nwe setup + ncs pulse)* t cpmck - 27.4 (ncs wr setup - nwe setup + ncs pulse)* t cpmck - 17.8 ??ns smc 26 ncs high to data out, nbs0/a0, nbs1, a1 - a23, change ncs wr hold * t cpmck - 7.6 ncs wr hold * t cpmck - 7.6 ??ns smc 27 ncs high to nwe inactive (ncs wr hold - nwe hold)* t cpmck - 7.8 (ncs wr hold - nwe hold)* t cpmck - 7.8 ??ns
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1098 figure 46-5. smc timings - ncs controlled read and write figure 46-6. smc timings - nrd controll ed read and nwe controlled write nrd ncs data nwe ncs controlled read with no hold ncs controlled read with hold ncs controlled write smc22 smc26 smc10 smc11 smc12 smc9 smc8 smc14 smc14 smc23 smc27 smc26 a0 - a23 smc24 smc25 smc12 smc13 smc13 nrd ncs data nwe a0-a23 nrd controlled read with no hold nwe controlled write with no hold nrd controlled read with hold nwe controlled write with hold smc1 smc2 smc15 smc21 smc3 smc4 smc15 smc19 smc20 smc7 smc21 smc16 smc7 smc16 smc19 smc21 smc17 smc18 smc5 smc5 smc6 smc6 smc17 smc18
1099 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.4.5 usart in spi mode timings timings are given in the following domains: ? 1.8v domain: vddio from 1.65v to 1.95v, maximum external capacitor = 10 pf ? 3.3v domain: vddio from 2.85v to 3.6v , maximum external capacitor = 10 pf figure 46-7. usart spi master mode figure 46-8. usart spi slave mode: (mode 1 or 2) nss spi 0 msb lsb spi 1 cpol=1 cpol=0 miso mosi sck spi 5 spi 2 spi 3 spi 4 spi 4 ? the mosi line is driven b y the outpu t pin txd ? the mis o line drives the input pin rxd ? the sck line is driven b y the output pin sck ? the nss line is driven b y the outpu t pin rts sck miso mosi spi 6 spi 7 spi 8 nss spi 12 spi 13 ? the mos i line drives the input pin rxd ? the miso line is driven b y the outpu t pin txd ? the s ck line drives the input pin sck ? the nss line drives the input pin cts
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1100 figure 46-9. usart spi slave mode: (mode 0 or 3) sck miso mosi spi 9 spi 10 spi 11 nss spi 14 spi 15
1101 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.4.5.1 usart spi timings table 46-13. usart spi timings symbol parameter conditions min max units master mode spi 0 sck period 1.8v domain 3.3v domain 6 / mck ? ? spi 1 input data setup time 1.8v domain 3.3v domain 0.5 * mck + 1.1 0.5 * mck + 1.1 ?? spi 2 input data hold time 1.8v domain 3.3v domain 1.5 * mck + 4.8 1.5 * mck + 4.8 ?? spi 3 chip select active to serial clock 1.8v domain 3.3v domain 1.5 * spck + 0.9 1.5 * spck + 0.9 ?? spi 4 output data setup time 1.8v domain 3.3v domain - 6.7 - 6.7 7.1 7.1 ns spi 5 serial clock to chip select inactive 1.8v domain 3.3v domain 1 * spck - 6.0 1 * spck - 6.0 ?ns slave mode spi 6 sck falling to miso 1.8v domain 3.3v domain 6.8 6.8 20.7 20.7 ns spi 7 mosi setup time before sck rises 1.8v domain 3.3v domain 2 * mck + 0.2 2 * mck + 0.2 ?ns spi 8 mosi hold time after sck rises 1.8v domain 3.3v domain 4.2 4.2 ?ns spi 9 sck rising to miso 1.8v domain 3.3v domain 8.1 8.1 19.8 19.8 ns spi 10 mosi setup time before sck falls 1.8v domain 3.3v domain 2 * mck + 1 2 * mck + 1 ?ns spi 11 mosi hold time after sck falls 1.8v domain 3.3v domain 5.2 5.2 ?ns spi 12 npcs0 setup to sck rising 1.8v domain 3.3v domain 2.5 * mck - 0.4 2.5 * mck - 0.4 ?ns spi 13 npcs0 hold after sck falling 1.8v domain 3.3v domain 1.5 * mck + 5.5 1.5 * mck + 5.5 ?ns spi 14 npcs0 setup to sck falling 1.8v domain 3.3v domain 2.5 * mck + 0.2 2.5 * mck + 0.2 ?ns spi 15 npcs0 hold after sck rising 1.8v domain 3.3v domain 1.5 * mck + 4.5 1.5 * mck + 4.5 ?ns
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1102 46.5 embedded analog periphe rals characteristics 46.5.1 core voltage regulator notes: 1. a ceramic capacitor must be connected between vddin and the closest gnd pin of the device. this decoupling capacitor is mandatory to reduce inrush cu rrent and to improve transient response and noise rejection. 2. to ensure stability, an external output capacitor, c out must be connected between the v ddout and the closest gnd pin of the device. the esr (equivalent series resistance) of the capacitor must be in the range of 0.01 to 10 . solid tantalum, and multilayer ceramic capacitors are all suitable as output capacitor. an additional 100 nf bypass capacitor between vddout and the closest gnd pin of the device helps decrease output noi se and improves the load transient response. 3. current needed to charge external bypass/decoupling capacitor network. 46.5.2 automatic power switch table 46-14. core voltage regulator characteristics symbol parameter condi tions min typ max unit v ddin supply voltage range (vddin) ? 1.62 3.3 3.6 v v ddout dc output voltage normal mode standby mode ? ? 1.2 0 ? ? v i load maximum dc output current v ddin > 2.0v, t j = 100c v ddin 2.0v, t j = 100c ? ? ? ? 120 40 ma acc output voltage total accuracy i load = 0.8 ma to 120 ma v ddin = 2.0v to 3.6v t j = [-40 c to 100 c ] -5 ? 5 % i inrush inrush current i load = 0. see note (3) ??400ma i ddin current consumption (vddin) normal mode; i load = 0 ma normal mode; i load = 120 ma standby mode ? ? ? 5 500 0.02 ? ? 1 a c in input decoupling capacitor (1) ?1 ? ? f c out output capacitor (2) capacitance esr 0.7 0.01 2.2 10 10 f t on turn-on time c out = 2.2f, v ddout reaches 1.2v ( 3%) ? 500 ? s t off turn-off time c out = 2.2f ? ? 40 ms table 46-15. automatic power switch characteristics symbol parameter condi tions min typ max unit v it+ positive-going input threshold voltage (vddio) ? 1.9?2.2v v it- negative-going input threshold voltage (vddio) ? 1.8?2.1v v it_hyst threshold hysteresis ? ? 100 ? mv
1103 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.5.3 lcd voltage regulator and lcd output buffers the lcd voltage regulator is a complete solution to drive an lcd display. it integrates a low-power ldo regulator with programmable output voltage and buffers to drive the lcd lines. a 1 f capacitor is required at the ldo regulator output (vddlcd). this regulator can be set in active (normal) mode, in bypass mode (hiz mode), or in off mode. ? in normal mode, the vddlcd ldo regulator output can be selected from 2.4v to 3.5v using lcdvrout bits in the supply controller mode regi ster (supc_mr), with the conditions: ? vddlcd vddio and, ? vddlcd vddin - 150 mv. ? in bypass mode (hiz mode), the vddlcd is set in high impedance (through the lcdmode bits in supc_mr register), and can be forced externally. th is mode can be used to save the ldo operating current (4 ua). ? in off mode, the vddlcd output is pulled down. important: when using an external or the internal voltage regulator, vddio and vd din must be still supplied with the conditions: 2.4v vddlcd vddio/vddin and vddio/vddin 2.5v. table 46-16. lcd voltage regulator characteristics symbol parameter condi tions min typ max unit v ddin supply voltage range (vddin) ? 2.5 ? 3.6 v v ddlcd programmable output range see table 46-17 . 2.4?3.5v output voltage accuracy -10 ? +10 % i ddin current consumption (v ddin) ldo enabled ? ? 4 a d vout / d vddin vddlcd variation with vddin ? ? -50 -70 mv/v i load output current dc or transient load averaged by the external decoupling capacitor ??2ma c out output capacitor on vddlcd ? 1 ? 10 f t on start-up time c out = 1f ? ? 1 ms table 46-17. vddlcd voltage selection at vddin = 3.6v lcd vrout vddlcd (v) lcd vrout vddlcd (v) lcd vrout vddlcd (v) lcd vrout vddlcd (v) 0 2.86 4 2.57 8 3.45 12 3.16 1 2.79 5 2.50 9 3.38 13 3.09 2 2.72 6 2.43 10 3.31 14 3.02 3 2.64 7 2.36 11 3.23 15 2.95
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1104 46.5.4 vddcore brownout detector note: 1. the product is guaranteed to be functional at v it- . figure 46-10. core brownout output waveform figure 46-11. core brownout transfer characteristics table 46-18. lcd buffers characteristics symbol parameter condi tions min typ max unit i ddin current consumption (vdd in) ldo enabled ? 25 35 a z out buffer output impedance gpio in lcd mode (seg or com) 200 500 1500 c load capacitive output load ? 10p ? 50n f t r / t f rising or falling time 95% convergence c load = 10 pf c load = 50 nf ?? 3 225 s table 46-19. core power supply brownout detector characteristics symbol parameter condi tions min typ max unit v it- negative-going input threshold voltage (vddcore) (1) ? 0.98 1 1.04 v v it+ positive-going input threshold voltage (vddcore) ?0 . 8 1 . 0 1 . 0 8 v v hyst hysteresis voltage v it+ - v it- ?2550mv t d- v it- detection propagation time vddcore = v it+ to ( v it- - 100mv) ? 200 300 ns t start start-up time from disabled state to enabled state ? ? 300 s i ddcore current consumption (vddcore) b rownout detector enabled ? ? 15 a i ddio current consumption (vddio) bro wnout detector enabled ? ? 18 a t vddcore v it - v it + bodcore_out t td+ td- vddcore increasing supply vhy st decreasing supply v it- bodcore_out v it+
1105 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.5.5 vddcore power-on-reset table 46-20. core power supply power-on-reset characteristics symbol parameter condi tions min typ max unit v it- negative-going input threshold voltage (vddcore) ? 0.71 0.9 1.02 v v it+ positive-going input threshold voltage (vddcore) ?0 . 8 1 . 0 1 . 0 8 v v hys hysteresis voltage v it+ - v it- ?60110mv t d- v it- detection propagation time vddcore = v it+ to (v it- - 100mv) ? ? 15 s t start start-up time vddcore rising from 0 to final value. time to release reset signal. ??300s i ddcore current consumption (vddcore) ? ? ? 6 a i ddio current consumption (vddio) ? ? ? 9 a
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1106 46.5.6 vddio supply monitor notes: 1. the average current consumption can be reduced by using the supply monitor in sampling mode. see the supply controller section. 2. v hyst = v th+ - v th- . v th+ is the positive-going input threshold voltage (vddio). table 46-21. vddio supply monitor symbol parameter condi tions min typ max unit v th- programmable range of negative- going input threshold voltage (vddio) 16 selectable steps 1.6 ? 3.4 v acc v th- accuracy with respect to programmed value -2.5 ? +2.5 % v hyst hysteresis (2) ?? 3 0 4 0 m v i ddon current consumption (vddio) (1) on with a 100% duty cycle. ? 20 40 a t on start-up time from off to on ? ? 300 s table 46-22. vddio supply monitor threshold selection digital code threshold typ (v) digital code threshold typ (v) digital code threshold typ (v) digital code threshold typ (v) 0000 1.6 0100 2.08 1000 2.56 1100 3.04 0001 1.72 0101 2.2 1001 2.68 1101 3.16 0010 1.84 0110 2.32 1010 2.8 1110 3.28 0011 1.96 0111 2.44 1011 2.92 1111 3.4
1107 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.5.7 vddbu po wer-on-reset figure 46-12. zero-power-on reset characteristics 46.5.8 vddio power-on-reset table 46-23. zero-power-on por (backup por) characteristics symbol parameter condi tions min typ max unit v th+ positive-going input threshold voltage (vddbu) at startup 1.45 1.53 1.59 v v th- negative-going input threshold voltage (vddbu) ? 1.351.451.55 v i ddbu current consumption enabled ? 300 700 na t res reset time-out period ? 100 240 500 s v it- v it+ vddbu porbu sw_out table 46-24. zero-power-on por (vddio por) characteristics symbol parameter condi tions min typ max unit v th+ positive-going input threshold voltage (vddio) at startup 1.45 1.53 1.59 v v th- negative-going input threshold voltage (vddio) ? 1.351.451.55 v i ddio current consumption ? ? 300 700 na t res reset time-out period ? 100 240 500 s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1108 46.5.9 32 khz rc oscillator 46.5.10 4/8/12 mhz rc oscillator note: 1. frequency range can be configured in the pmc clock generator. table 46-25. 32 khz rc oscillator characteristics symbol parameter conditions min typ max unit v ddbu supply voltage range (vddbu) ? 1.62 3.3 3.6 v f 0 frequency initial accuracy vddbu = 3.3v, t a = 27 c 26 32 39 khz d f /d v frequency drift with vddbu vddbu from 1.6v to 3.6v 0.5 1.5 2.5 %/v df/dt frequency drift with temperature t a = [-40c to +27c] ? +8 +17 % t a = [27c to 85c] ? +6 +13 duty duty cycle ? 48 50 52 % t on start-up time ? ? ? 100 s i ddon current consumption (vddbu) ? ? 150 300 na table 46-26. 4/8/12 mhz rc oscillators characteristics symbol parameter conditions min typ max unit v ddcore supply voltage range (vddcore) ? 1.08 1.2 1.32 v f range output frequency range (1) ?4 ? 1 2 m h z acc 4 4 mhz range; total accuracy -40c < t a < +85c ? ? 30 % acc 8 8 mhz range; total accuracy vddcore from 1.08v to 1.32v t a = 25c 0c < t a < +70c -40c < t a < +85c ?? 1.0 3.0 5 % acc 12 12 mhz range; total accuracy vddcore from 1.08v to 1.32v t a = 25c 0c < t a < +70c -40c < t a < +85c ?? 1.0 3.0 5 % f step frequency trimming step size 8 mhz 12 mhz ? 47 64 ?khz duty duty cycle ? 45 50 55 % t on startup time, moscrcen from 0 to 1 ? ? ? 10 s t stab stabilization time on rc frequency change (moscrcf) ?? ? 5 s i ddon active current consumption (vddcore) 4mhz 8mhz 12 mhz ? 50 65 82 68 86 102 a
1109 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.5.11 32.768 khz crystal oscillator note: 1. r s is the series resitor. figure 46-13. 32.768 khz crystal oscillator schematic c lext32k = 2 (c crystal ? c para32k ? c pcb / 2) where c pcb is the ground referenced parasitic capacitance of the printed circuit board (pcb) on xin32 and xout32 tracks. as an example, if the crystal is specified for a 12.5 pf load, with c pcb =1 pf (on xin32 and on xout32), c lext32k = 2 x (12.5 - 0.7 - 0.5) = 22.6 pf. table 46-27. 32.768 khz crystal oscillator characteristics symbol parameter conditions min typ max unit v ddbu supply voltage range (vddbu) ? 1.62 3.3 3.6 v f req operating frequency normal mode with crystal ? ? 32.768 khz duty duty cycle ? 40 50 60 % t on start-up time r s (1) < 50 k r s (1) < 100 k c crystal = 12.5 pf c crystal = 6 pf c crystal = 12.5 pf c crystal = 6 pf ?? 900 300 1200 500 ms i ddon current consumption (vddbu) r s (1) < 65 k r s (1) < 100 k r s (1) < 20 k c crystal = 12.5 pf c crystal = 6 pf c crystal = 6 pf c crystal = 6 pf ? 450 280 350 220 950 850 1050 na p on drive level ? ? ? 0.1 w r f internal resistor between xin32 and xout32 ? 10 ? m c crystal allowed crystal capacitive load from crystal specification. 6 ? 12.5 pf c lext32k external capacitor on xin32 and xout32 ???24pf c para32k internal parasitic capacitance between xin32 and xout32 0.6 0.7 0.8 pf xin32 xout32 c lext32k c lext32k sam4 c para32k c pcb c pcb
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1110 table 46-28 below summarizes recommendations for 32.768 khz crystal selection. 46.5.12 3 to 20 mhz crystal oscillator notes: 1. r s = 100-200 ohms; c s = 2.0 - 2.5 pf; c m = 2 ? 1.5 ff(typ, worst case) using 1 k serial resistor on xout. 2. r s = 50-100 ohms; c s = 2.0 - 2.5 pf; c m = 4 - 3 ff(typ, worst case). 3. r s = 25-50 ohms; c s = 2.5 - 3.0 pf; c m = 7 - 5 ff (typ, worst case). 4. r s = 20-50 ohms; c s = 3.2 - 4.0 pf; c m = 10 - 8 ff(typ, worst case). table 46-28. recommended crystal characteristics symbol parameter condi tions min typ max unit esr equivalent series resistor (r s) crystal @ 32.768 khz ? 50 100 k c m motional capacitance crystal @ 32.768 khz 0.6 ? 3 ff c shunt shunt capacitance crystal @ 32.768 khz 0.6 ? 2 pf table 46-29. 3 to 20 mhz crystal oscillator characteristics symbol parameter conditions min typ max unit v ddio supply voltage range (vddio) 1.62 3.3 3.6 v v ddpll supply voltage range (vddpll) 1.08 1.2 1.32 v f osc operating frequency range normal mode with crystal 3 16 20 mhz duty duty cycle 40 50 60 % t on start-up time 3 mhz, c shunt = 3pf 8 mhz, c shunt = 7pf 16 mhz, c shunt = 7pf with c m = 8 ff 16 mhz, c shunt = 7pf with c m = 1.6 ff 20 mhz, c shunt = 7pf ?? 14.5 4 1.4 2.5 1 ms i dd_on current consumption on vddio on vddpll 3 mhz (1) 8 mhz (2) 16 mhz (3) 20 mhz (4) 3 mhz (1) 8 mhz (2) 16 mhz (3) 20 mhz (4) ? 230 300 390 450 6 12 20 24 350 400 470 560 7 14 23 30 a p on drive level 3 mhz 8 mhz 16 mhz, 20 mhz ?? 15 30 50 w r f internal resistor between xin and xout ? 0.5 m c crystal allowed crystal capacitive load from crystal specification 12 ? 18 pf c lext external capacitor on xin and xout ? ? ? 18 pf c lint integrated load capacitance between xin and xout 7.5 9.5 10.5 pf
1111 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-14. 3 to 20 mhz crystal oscillator schematic c lext = 2 x ( c crystal ? c lint ? c pcb / 2 ). where c pcb is the ground referenced parasitic capacitance of the printed circuit board (pcb) on xin and xout tracks. as an example, if the crystal is specified for a 18 pf load, with c pcb =1 pf (on xin and on xout), c lext = 2 x (18 - 9.5 - 0.5) = 16 pf. table 46-30 summarizes recommendations to be followed when choosing a crystal. 46.5.13 crystal oscillator design considerations when choosing a crystal for the 32768 hz slow clock oscillator or fo r the 3-20 mhz oscillato r, several parameters must be taken into account. impo rtant parameters are as follows: ? crystal load capacitance. the total capacitance loading the crysta l, including the oscillator?s internal parasitics and the pcb parasitics, must match the load capacitance for which the crystal? s frequency is specified. any mismatch in the load capacitance with respect to the crystal?s specificat ion will lead to inaccura te oscillation frequency. ? crystal drive level. use only crystals with the specified drive levels greater than the specified mcu oscillator drive level. applications that do not respect th is criterion may damage the crystal. ? crystal equivalent series resistor (esr). use only crystals with the specified esr lower than the specified mcu oscillator esr. in applications where this criterion is not respected, the crystal oscilla tor may not start. ? crystal shunt capacitance. use only crystal with the specified shunt capitanc e lower than the specif ied mcu oscillator shunt capacitance. in applications where th is criterion is not re spected, the crystal o scillator may not start. ? pcb layout considerations. to minimize inductive and capacitive parasitics asso ciated with xin, xout, xin3 2, xout32 nets, it is recommended to route them as short as possible. it is also of prime importance to keep those nets away xin xout c lext c lint c lext sam4 r = 1k if crystal frequency is lower than 8 mhz c pcb c pcb table 46-30. recommended crystal characteristics symbol parameter condi tions min typ max unit esr equivalent series resistor (r s ) fundamental @ 3 mhz fundamental @ 8 mhz fundamental @ 12 mhz fundamental @ 16 mhz fundamental @ 20 mhz ?? 200 100 80 80 50 c m motional capacitance ? ? ? 8 ff c shunt shunt capacitance ? ? ? 7 pf
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1112 from noisy switching signals (clock, data, pwm, etc.). a good pratice is to shield them with a quiet ground net to avoid coupling to neighboring signals. 46.5.14 plla, pllb characteristics table 46-31. plla characteristics symbol parameter conditions min typ max unit v ddpll supply voltage range (vddpll) ? 1.08 1.2 1.32 v f in input frequency range ? 30 32.768 34 khz f out output frequency range ? 7.5 8.192 8.5 mhz n ratio frequency multiplying ratio (mula +1) ? ? 250 ? ? j p period jitter peak value ? 4 ? ns t on start-up time from off to output oscillations (output frequency within 10% of target frequency) ? ? 250 s t lock lock time from off to pll locked ? ? 2.5 ms i pllon active mode current consumption (vddpll) f out = 8.192 mhz ? 50 ? a i plloff off mode current consumption (vddpll) @25 c over the temperature range ? 0.05 0.05 0.30 5 a table 46-32. pllb characteristics symbol parameter conditions min typ max unit v vddpll supply voltage range (vddpll) ? 1.08 1.2 1.32 v f in input frequency range ? 3 ? 32 mhz f out output frequency range ? 80 ? 240 mhz n ratio frequency multiplying ratio (mulb +1) ? 3 ? 62 ? q ratio frequency dividing ratio (divb) ? 2 ?24? t on start-up time ? ? 60 150 s idd pll current consumption on vddpll active mode @ 80 mhz @1.2v active mode @ 96 mhz @1.2v active mode @ 160 mhz @1.2v active mode @ 240 mhz @1.2v ? 0.94 1.2 2.1 3.34 1.2 1.5 2.5 4 ma
1113 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.5.15 temperature sensor characteristics the temperature sensor prov ides an output voltage (v t ) that is proportional to absolute temperature (ptat). this voltage can be measured through the channel number 7 of the 10-bit adc. improvem ent of the raw performance of the temperature sensor acquisition can be achieved by performing a single temperature point calibration to remove the initial inaccuracies (v t and adc offsets). note: 1. does not include errors due to a/d conversion process. 46.5.16 optical uart rx transceiver characteristics table 46-34 gives the description of the optical link transceiver for electrically isolated serial communication with hand-held equipment, such as calibrators compliant with ansi-c12.18 or iec62056-21 norms (only available on uart1). table 46-33. temperature sensor characteristics symbol parameter condi tions min typ max unit v ddin supply voltage range (vddin) ? 2.4 ? 3.6 v v t output voltage t j = 27 c 1.34 1.44 1.54 v dv t /dt output voltage sensitivity to temperature ? 4.2 4.7 5.2 mv/c dv t /dv v t variation with vddin vddin from 2.4v to 3.6v ? ? 1 mv/v t s v t settling time when v t is sampled by the 10-bit adc, the required track time to ensure 1c accurate settling ??1s t acc temperature accuracy (1) after offset calibration over t j range [-40c to +85c] ?5?c after offset calibration over t j range [0c to +80c] ?4?c t on start-up time ? ? 5 10 s i vddin current consumption ? 50 70 80 a table 46-34. transceiver characteristics symbol parameter condi tions min typ max unit v ddio supply voltage range (vddio) ? 3 3.3 3.6 v i dd current consumption on off ? 25 35 0.1 a v th comparator threshold according to the programmed threshold. see the opt_cmpth bit in the uart mode register (uart1) -20 ? +20 mv v hyst hysteresis ? 10 20 40 mv t prop propagation time with 100 mvpp square wave input around threshold ??5s t on start-up time ? ? ? 100 s
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1114 46.5.17 10-bit adc characteristics note: 1. average current consumption performing co nversion in free run mode @ 16 mhz adc clock. f s = 510 ks/s. note: 1. advref input range limited to vddio if vddio < vddin. notes: 1. t conv = (tracktim + 24) / f ck_adc . 2. f s = 1 / t conv . 3. refer to section 46.5.17.1 ?track and hold time versus s ource output impedance, effective sampling rate? . table 46-35. adc power supply characteristics symbol parameter condi tions min typ max unit v ddin supply voltage range (vddin) ? 2.4 3.3 3.6 v i vddin current consumption on vddin adc on (1) , internal voltage reference on generating advref = 3.0v ? 450 700 a adc on (1) , internal voltage reference off, advref externally supplied ? 220 350 table 46-36. adc voltage reference input characteristics (advref pin) symbol parameter condi tions min typ max unit v advref advref input voltage range (1) internal voltage reference off 2.4 ? v ddin v r advref advref input resistance adc on, internal voltage reference off 91419k i advref current consumption on advref advref = 2.4v -35% 170 +35% a advref = 3.3v 235 advref = 3.6v 260 c advref decoupling capacitor on advref ? 100 ? ? nf table 46-37. adc timing characteristics symbol parameter condi tions min typ max unit f ck_adc adc clock frequency 3.0v v ddin 3.6 2.4v v ddin 3.0 ?? 16 14 mhz t conv adc conversion time (1) f ck_adc = 16 mhz, t track = 500 ns 1.95 ? ? s f s sampling rate (2) v ddin > 3v, f ck_adc = 16 mhz v ddin > 2.4v, f ck_adc = 14 mhz ?? 510 380 ks/s t on start-up time adc only ? ? 40 s t track track and hold time (3) 2.4v v ddin 3.0 3.0v < v ddin <3.6v 1000 500 ??ns
1115 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 notes: 1. if v vddio < v advref , full scale range is limited to vddio. 2. see figure 46-15 ?simplified acquisition path? . note: 1. in this table, values expressed in lsb refer to the native adc resolution (i.e. a 10-bit lsb). table 46-38. adc analog input characteristics symbol parameter conditions min typ max unit fsr analog input full scale range (1) ?0 ? v advref v c in input capacitance (2) accounts for i/o input capacitance + adc sampling capacitor ? ? 10 pf table 46-39. static performance characteristics (1) symbol parameter condi tions min typ max unit r adc native adc resolution ? ? 10 ? bits r adc_av resolution with digital averaging see ?adc controller? section 10 ? 12 bits inl integral non linearity f ck_adc = 16 mhz errors with respect to the best fit line method -2 ? +2 lsb dnl differential non linearity -1 ? +1 lsb oe offset error -5 ? 5 lsb ge gain error -3 ? +3 lsb table 46-40. dynamic performance characteristics symbol parameter conditions min typ max unit snr signal to noise ratio f ck_adc = 16 mhz, v advref = v ddin , f in = 50 khz, v inpp = 0.95 x v advref 57 60 ? db thd total harmonic distortion ? -68 -55 db sinad signal to noise and distortion 52 59 ? db enob effective number of bits 8.3 9.6 ? bits
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1116 46.5.17.1track and hold time versus source output impedance, effective sampling rate the following figure gives a simplified view of the acquisition path. figure 46-15. simplified acquisition path during its tracking phase, the 10-bit adc charges its sa mpling capacitor through variou s serial resistors: source output resistor, multiplexer series resistor and the sampling switch series resi stor. in case of high output source resistance (low power resistive divider, for example), the track time must be increased to ensure full settling of the sampling capacitor voltage. the following formulas give th e minimum track time that guarantees a 10-bit accurate settling: ? v ddin > 3.0v: t track (ns) = 0.12 x r source ( ) + 500 ? v ddin 3.0v: t track (ns) = 0.12 x r source ( ) + 1000 according to the calculated track time ( t track ), the actual track time of the adc must be adjusted through the tracktim field in the adc_mr register. tr acktim is obtained by the following formula: with t ck_adc = 1 / f ck_adc and floor(x) the mathematical function that rounds x to the greatest previous integer. the actual conversion time of the converte r is obtained by the following formaula: when converting in free run mode, the actual sampling rate of the converter is (1 / t conv ) or as defined by the following formula: the maximum source resistance with the actu al tracktim setting is: ? r source_max ( ) = (( tracktim + 1) x t ck_adc (ns) - 500) / 0.12 for v ddin > 3.0v; or ? r source_max ( ) = (( tracktim + 1) x t ck_adc (ns) - 1000) / 0.12 for v ddin 3.0v tr a ck & hold mux. zsource ron csample adc input 10-bit adc core vddio sam4 tracktim = floor t track t ck_adc () t conv = (tracktim + 24) x t ck_adc f ck_adc (tracktim + 24) f s =
1117 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 example: calculated track time is lower than actual adc clock period ? assuming: f ck_adc = 1 mhz (t ck_adc = 1 s), r source = 100 and v ddin = 3.3v ? the minimum required track time is: t track = 0.12 x 100 + 500 = 512 ns ? t track being less than t ck_adc , tracktim is set to 0. actual track time is t ck_adc = 1 s ? the calculated sampling rate is: f s = 1 mhz / 24 = 41.7 khz ? the maximum allowable source resistance is: r source_max = (1000 - 500) / 0.12 = 4.1 k example: calculated track time is greater than actual adc clock period ? assuming: f ck_adc = 16 mhz (t ck_adc = 62.5ns), r source = 600 and v ddin = 2.8v ? the minimum required track time is: t track = 0.12 x 600 + 1000 = 1072 ns ? tracktim = floor (1072 / 62.5) = 17. actual track time is: (17 + 1) x t ck_adc = 1.125 s ? the calculated sampling rate is: f s = 16 mhz / (24 + 17) = 390.2 khz ? the maximum allowable source resistance is : r source_max = (1125 - 1000) / 0.12 = 1.04 k
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1118 46.5.18 programmable voltage reference characteristics sam4cm embeds a programmable voltage reference de signed to drive the 10-bit adc advref input. table 46- 41 shows the electrical characteristics of this internal voltage reference. in ca se of need, this voltage reference can be bypassed with some level of configur ability: the user can either choose to feed the advref input with an external voltage source or with the vddio internal power rail. see programming details in the adc analog control register (adc_acr) in the section analog-to- digital converter (adc) in this datasheet. notes: 1. tc = ( max( v advref ) - min( v advref ) ) / ( (t max - t min ) * v advref (25c) ). 2. does not include the current consumed by the adc advref input if adc is on. note: 1. voltage reference values are configurable in adc_acr.irvs. table 46-41. programmable voltage reference characteristics symbol parameter conditions min typ max unit v ddin voltage reference supply range ? 2 ? 3.6 v v advref programmable output range see table 46-42 . v ddin > v advref + 100mv 1.6 ? 3.4 v acc reference voltage accuracy with respect to the programmed value. v ddin = 3.3v; t j = 25c -3 ? 3 % t c temperature coefficient box method (1) ??250ppm/c t on start-up time v ddin = 2.4v v ddin = 3v v ddin = 3.6v ?? 100 70 40 s z load load impedance resistive 4 ? ? k f capacitive 0.1 ? 1 i vddin current consumption on vddin (2) adc is off ? 20 30 a table 46-42. programmable voltage reference selection values sel. value (1) advref notes 0 2.40 default value 12 . 2 8 ? 22 . 1 6 ? 32 . 0 4 ? 41 . 9 2 ? 51 . 8 0 ? 61 . 6 8 ? 7 1.55 min value 8 3.38 max value 93 . 2 5 ? a3 . 1 3 ? b3 . 0 1 ? c2 . 8 9 ? d2 . 7 7 ? e2 . 6 5 ? f2 . 5 3 ?
1119 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.5.19 emafe characteristics unless otherwise specified, external components characteristics according to the typical application diagram in the emafe section are as follows: ? c vref =1 f and c vdda =1 f ? emafe clock = 4.096 mhz ? v ddin_afe = v ddio = 3.3v ? noise bandwidth = [30 hz, 2 khz] for me asurement channels characteristics ? t j = [-40c ; +100c] note: 1. in case of power fail conditions on vddi o, this por only resets emafe related settings. table 46-43. emafe power supply characteristics symbol parameter comments min typ max units v vddin_afe supply voltage range (vddin_afe) ? 3.0 3.3 3.6 v v vddio supply voltage range (vddio) ? 3.0 3.3 3.6 v vdda supply voltage range (vdda) ? 2.7 2.8 2.9 v i ddon current consumption on (vddin_afe + vddio) emafe clock @ 4.096 mhz v vddio = v vddin_afe = 3.3v k channels on (k 1), voltage reference on, vdda ldo regulator on. ? 1.4 + k 0.75 ?ma table 46-44. emafe vddio power-on-reset thresholds (1) symbol parameter comments min typ max units v t_rise v ddio rising threshold dc level 2.5 2.6 2.8 v v t_fall v ddio falling threshold dc level 2.35 2.5 2.65 v v t_hyst v t_rise - v t_fall ? 90 120 180 mv table 46-45. current or voltage measureme nt channel electrical characteristics symbol parameter comments min typ max units v vdda operating supply voltage ? 2.7 2.8 2.9 v i ddon channel supply current (1) in vddio and vdda off ? ? 0.2 a on ? 0.75 1 ma f emafe_clk master clock input frequency ? 3.9 4.096 4.3 mhz v ind_fs a/d converter input referred full scale voltage (2) v ref = 1.2v v ind = v vpx or v ind = v ipx - v inx g: channel gain = {1, 2, 4 or 8} ? 1.2 / g ? v pp v cm_in common mode input voltage range (v ipx + v inx ) / 2 -20?20mv z in0 common mode input impedance at t j0 = 23c g: channel gain = {1, 2, 4 or 8} on v px , v ipx , v inx pins. f emafe_clk = 4.096 mhz 400 / g 480 / g 560 / g k
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1120 notes: 1. current consumptio n per measurement channel. 2. v ind may be limited by the recommended input voltage on analog input pins (+/-0.25v, see table 46-3 ?recommended operating conditions on input pins? ). 3. corresponds to the maximum signal on the voltage channel(s). 4. includes the input impeda nce drift with temperature. note: 1. tc is defined using the box method: tc = ( v ref_afe_max - v ref_afe_min ) / ( v ref_afe0 x ( t max - t min ) ). sinad peak peak signal to noise and distortion ratio. f in = 45 hz to 66 hz bw = [30hz, 2 khz] gain = 1, v ind = 1.000 v pp ?84? db gain = 1, v ind = 0.500 v pp (3) ?78? gain = 2, v ind = 0.500 v pp ?84? gain = 4, v ind = 0.250 v pp ?82? gain = 8, v ind = 0.125 v pp ?81? e n input referred noise voltage integrated over [30 hz, 2 khz] gain = 1 ? 21 ? v rms gain = 2 ? 10 ? gain = 4 ? 6 ? gain = 8 ? 3.3 ? s n input referred noise voltage density at fundamental frequency. (between 45 hz and 66 hz). gain = 1 ? 470 ? nv/ hz gain = 2 ? 220 ? gain = 4 ? 130 ? gain = 8 ? 73 ? eg 0 gain error t j0 = 23c; v ref = 1.2v -3 ? 3 % tc g channel gain drift with temperature (4) -40c < t j < 100c, v ref = 1.2v r source = 3k ?-5?ppm /c v os0 input referred offset t j0 = 23c -5 / g ? 5 / g mv tc vos v os drift with temperature -40c < t j < 100c -2 ? +2 v/c table 46-46. emafe precision voltage reference and die temperature sensor characteristics symbol parameter comments min typ max units v vdda operating supply voltage ? 2.7 2.8 2.9 v i vdda supply current off ? ? 0.1 a on ? 70 100 v ref_afe0 output voltage initial accuracy at t j0 = 23c 1.142 1.144 1.146 v tc vref_u v ref drift with temperature (1) uncompensated. ? 50 ? ppm /c tc vref_c using factory programmed calibration registers. ?10? r out v ref_afe output resistance ? 200 500 800 k d temp_lin die temperature sensor, digital reading linearity ??2?c i vref_off current in vref pin when internal voltage reference is off ? -100 ? 100 na table 46-45. current or voltage measurement ch annel electrical characteristics (continued) symbol parameter comments min typ max units
1121 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 table 46-47. emafe vdda ldo regulator symbol parameter comments min typ max units v vddin operating supply voltage ? 3.0 3.3 3.6 v i vddin supply current off ? ? 0.1 a on ? ? 250 i o output current ? ? ? 15 ma v o dc output voltage i o = 0 ma. 2.75 2.8v 2.85 v v o / i o static load regulation i o : 0 to i omax -5 ? ? mv/ma v o / v ddin static line regulation v ddin : 3.0 to 3.6v -5 ? 5 mv/v psrr power supply rejection ratio f = dc to 2000 hz ? 40 ? db f = 1 mhz ? 40 ? t on start-up time v o from 0 to 95% of final value. i o = 0 ma. ??1ms c o stable output capacitor range capacitive 0.5 1 4.7 f resistive 5 10 300 m
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1122 46.6 embedded flash characteristics 46.6.1 embedded flash dc characteristics 46.6.2 embedded flash ac characteristics table 46-48. dc flash characteristics symbol parameter conditions typ max unit i cc active current random 128-bit read: maximum read frequency onto v ddcore = 1.2v @ 25c maximum read frequency onto v ddio = 3.3v @ 25c 16 3 25 5 ma random 64-bit read: maximum read frequency onto v ddcore = 1.2v @ 25c maximum read frequency onto v ddio = 3.3v @ 25c 10 3 18 5 ma program: - onto v ddcore = 1.2v @ 25c - onto v ddio = 3.3v @ 25c 3 10 5 15 ma erase: - onto v ddcore = 1.2v @ 25c - onto v ddio = 3.3v @ 25c 3 10 5 15 ma table 46-49. ac flash characteristics parameter conditions min typ max unit program/ erase operation cycle time write page (512 bytes) ? 1.5 3 ms erase page ? 10 50 ms erase block (4 kbytes) ? 50 200 ms erase sector ? 400 950 ms full chip erase - 1 mbytes - 512 kbytes ? 9 5.5 18 11 s lock/unlock time per region ? 1.5 3 ms data retention not powered or powered ? 20 ? years endurance write/erase cycles per page, block or sector @ 85c 10k ? ? cycles
1123 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.6.2.1 sam4cm8/16 flash wait states and operating frequency the maximum operating frequency given in table 46-50 below is limited by the embedded flash access time when the processor is fetching code out of it. the table give the dev ice maximum operating frequency depending on the fws field of the efc_fmr register. this field defines the number of wait states required to access the embedded flash memory. 46.6.2.2 sam4cm32 flash wait states and operating frequency the maximum operating frequency given in table 46-51 below is limited by the embedded flash access time when the processor is fetching code out of it. the table give the dev ice maximum operating frequency depending on the fws field of the efc_fmr register. this field defines the number of wait states required to access the embedded flash memory. table 46-50. flash wait state versus operating frequency fws (flash wait state) maximum operating frequency (mhz) @ t a = 85c vddcore = 1.08v vddio = 1.62v to 3.6v vddcore = 1.2v vddio = 1.62v to 3.6v vddcore = 1.08v vddio = 2.7v to 3.6v vddcore = 1.2v vddio = 2.7v to 3.6v 016 17 20 21 133 35 40 42 251 52 61 63 367 70 81 85 485 87 98 106 5 100 105 ? 120 6? 121 ? ? table 46-51. flash wait state versus operating frequency fws (flash wait state) maximum operating frequency (mhz) @ t a = 85c vddcore = 1.08v vddio = 1.62v to 3.6v vddcore = 1.2v vddio = 1.62v to 3.6v vddcore = 1.08v vddio = 2.7v to 3.6v vddcore = 1.2v vddio = 2.7v to 3.6v 016 17 20 21 133 34 40 42 250 52 60 63 367 69 80 83 484 86 91 104 591 104 ? 118 6? 114 ? ?
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1124 46.7 power supply current consumption this section provides information about the current c onsumption on different power supply rails of the device. it gives current consumption in low-power modes (backup mode, wait mode, sleep mode) and in active mode (the application running from memory, by peripheral). 46.7.1 backup mode current consumption backup mode configurations and measurements are defined as follows: ? configuration a is used to achieve the lowest possible current consumption, ? configurations b, c and d are typica l use cases with crystal oscillator, lcd and anti-tamper pins enabled. reminder: in backup mode, the core voltage regulator is off and thus all the digital functions powered by vddcore are off. 46.7.1.1 backup mode configuration a: embe dded slow clock rc oscillator enabled ? por backup on vddbu is disabled ? rtc running ? rtt enabled on 1 hz mode ? force wake-up (fwup) enabled ? current measurement as per figure 46-16 46.7.1.2 backup mode config uration b: 32.768 khz crystal oscillator enabled ? por backup on vddbu is disabled ? rtc running ? rtt enabled on 1 hz mode ? force wake-up (fwup) enabled ? anti-tamper input tmp0 enabled ? current measurement as per figure 46-16 figure 46-16. measurement setup for configurations a and b amp1 vddin vddout vddcore 1.6v to 3.6v vddbu sam4 vddpll vddlcd vddio
1125 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-17. typical current consumption in backup mode for configurations a and b table 46-52. sam4cm8/16 typical current consumption values for backup mode configurations a and b conditions configuration a configuration b unit vddbu = 3.6v @25c vddbu = 3.3v @25c vddbu = 3.0v @25c vddbu = 2.5v @25c vddbu = 1.6v @25c 580 520 480 440 400 760 700 680 640 600 na vddbu = 3.6v @85c vddbu = 3.3v @85c vddbu = 3.0v @85c vddbu = 2.5v @85c vddbu = 1.6v @85c 1.57 1.5 1.44 1.3 1.16 1.8 1.7 1.65 1.56 1.43 a table 46-53. sam4cm32 typical current consumption values for backup mode configurations a and b conditions configuration a configuration b unit vddbu = 3.6v @25c vddbu = 3.3v @25c vddbu = 3.0v @25c vddbu = 2.5v @25c vddbu = 1.6v @25c 980 900 870 740 610 1100 1000 960 870 720 na vddbu = 3.6v @85c vddbu = 3.3v @85c vddbu = 3.0v @85c vddbu = 2.5v @85c vddbu = 1.6v @85c 1.87 1.76 1.67 1.54 1.36 2.2 2.1 2 1.9 1.74 a sam4cm8/16 sam4cm32 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 iddbu (ua) vddbu (v) config. a (25c) config. a (85c) config. b (25c) config. b (85c) 85c 25c a a b b 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 iddbu (ua) vddbu (v) config. a (25c) config. a (85c) config. b (25c) config. b (85c) 85c 25c a a b b
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1126 46.7.1.3 backup mode config uration c: 32.768 khz crystal oscillator enabled ? por backup on vddbu is disabled ? rtc running ? rtt enabled on 1 hz mode ? force wake-up (fwup) enabled ? anti-tamper input tmp0, tmp1 and rtcout0 enabled ? main crystal oscillator disabled ? system io lines pa30, pa31, pb[0 ...3] in gpio input pull-up mode ? all other gpio lines in default state (see pio multiplexing table) ? current measurement as per figure 46-18 46.7.1.4 backup mode configurat ion d: 32.768 khz crystal oscillator and lcd enabled ? por backup on vddbu is disabled ? rtc running ? rtt enabled on 1 hz mode ? lcd controller in low power mode, static bias and x64 slow clock buffer on-time drive time ? lcd voltage re gulator used ? force wake-up (fwup) enabled ? anti-tamper input tmp0, tmp1 and rtcout0 enabled ? main crystal oscillator disabled ? system io lines pa30, pa31, pb [0..3] in gpio input pull-up mode ? all other gpio lines in default state (see pio multiplexing table) ? current measurement as per figure 46-18 figure 46-18. measurement setup for configuration c and d note: no current is drawn on vddin power input in backup mode. the pin vddin can be left unpowered in backup mode. amp1 vddin vddout vddcore 3v amp2 2.5v to 3.6v vddbu sam4 vddpll rtcout tmp[0...3] vddlcd vddio comx segx
1127 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-19. typical current consumption in backup mode for configurations c and d table 46-54. sam4cm8/16 typical current consumption values for backup mode configurations c and d conditions configuration c configuration d unit idd_bu - amp1 idd_in/io - amp2 idd_bu - amp1 idd_in/io - amp2 vddio = 3.6v @25c vddio = 3.3v @25c vddio = 3.0v @25c vddio = 2.5v @25c 0.05 3.6 3.3 2.9 2.4 0.05 10.5 9.9 9.3 8.3 a vddio = 3.6v @85c vddio = 3.3v @85c vddio = 3.0v @85c vddio = 2.5v @85c 0.09 7.8 7.2 6.7 5.7 0.1 15.9 15.0 14.4 13.2 table 46-55. sam4cm32 typical current consumption values for backup mode configurations c and d conditions configuration c configuration d unit idd_bu - amp1 idd_in/io - amp2 idd_bu - amp1 idd_in/io - amp2 vddio = 3.6v @25c vddio = 3.3v @25c vddio = 3.0v @25c vddio = 2.5v @25c 0.05 4.5 4.0 3.6 3.1 0.05 10.7 9.9 9.1 8.3 a vddio = 3.6v @85c vddio = 3.3v @85c vddio = 3.0v @85c vddio = 2.5v @85c 0.09 10.7 9.8 9.0 7.9 0.1 18.2 16.9 15.9 14.3 sam4cm8/16 sam4cm32 0 2 4 6 8 10 12 14 16 18 20 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 iddio/in (ua) vddio/in (v) config. c (25c) config. c (85c) config. d (25c) config. d (85c) 85c 25c c c d d 0 2 4 6 8 10 12 14 16 18 20 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 iddio/in (ua) vddio/in (v) config. c (25c) config. c (85c) config. d (25c) config. d (85c) 85c 25c c c d d
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1128 46.7.2 wait mode current consumption wait mode configuration and measurements are defined in section 46.7.2.1 ?wait mode configuration? . reminder: in wait mode, the core voltage regulator is on , but the device is not clocked. flash power mode can be either in standby mode or deep power-down mode. wait mode provides a much faster wake-up compared to backup mode. 46.7.2.1 wait mode configuration ? 32.768 khz crystal oscillator running ? 4 mhz rc oscillator running ? main crystal and plls stopped ? rtc running ? rtt enabled on 1 hz mode. ? one wake-up pin (wkupx) used in fast wake-up mode ? anti-tamper inputs tmp0, tmp1 and rtcout0 enabled ? system io lines pa30, pa31, pb[0 ...3] in gpio input pull-up mode ? all other gpio lines in default state ? current measurement as per figure figure 46-20. measurement setup for wait mode configuration amp1 vddin vddout vddcore 3v amp2 amp3 3.3v vddbu sam4 vddpll vddlcd vddio
1129 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 table 46-56. sam4cm8/16 typical current consumption in wait mode conditions idd_bu - amp1 idd_in/io - amp2 idd_core - amp3 unit @25c @85c @25c @85c @25c @85c flash in read-idle mode 0.003 0.09 68 500 45 470 a flash in standby mode 0.003 0.09 66 500 45 470 flash in deep power-down mode 0.003 0.09 62 500 45 470 table 46-57. sam4cm32 typical current consumption in wait mode conditions idd_bu - amp1 idd_in/io - amp2 idd_core - amp3 unit @25c @85c @25c @85c @25c @85c flash in read-idle mode 0.003 0.09 100 760 62 700 a flash in standby mode 0.003 0.09 100 760 62 700 flash in deep power-down mode 0.003 0.09 90 740 62 700
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1130 46.7.3 sleep mode current consumption sleep mode configuration and measur ements are defined in this section. reminder: the purpose of sleep mode is to optimize po wer consumption of the device versus response time. in this mode, only the core clocks of cm4p0 and/or cm4p1 are stopped. figure 46-21. measurement setup for sleep mode ? vddio = vddin = 3.3v ? vddcore = 1.2v (internal voltage regulator used) ? t a = 25 c ? core 0 clock (hclk) and core 1 (cphclk) clock stopped ? sub-system 0 master clock (mck), sub-system 1 ma ster clock (cpbmck) running at various frequencies (pllb used for frequencies above 12 mhz, fast rc osci llator at 12 mhz for the 12 mhz point, and fast rc oscillator at 8 mhz divided by 1/ 2/4/8/16/32 for lower frequencies) ? all peripheral clocks deactivated ? no activity on i/o lines ? vddpll not taken into account. see pll characteristics for further details ? current measurement as per figure 46-21 amp1 vddin vddout vddcore 3.3v amp2 vddbu sam4cm vddpll vddlcd vddio amp3
1131 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 table 46-58. sam4cm8/16 typical sleep mode current consumption versus frequency master clock (mhz) idd_in - amp1 idd_io - amp2 idd_core - amp3 unit 120 14.26 0.22 10.83 ma 100 11.96 0.22 9.09 84 10.1 0.22 7.68 64 7.78 0.22 5.92 48 5.93 0.22 4.48 32 5.02 0.22 3.16 24 3.85 0.22 2.4 12 1.26 0.03 1.21 8 0.88 0.03 0.83 4 0.5 0.03 0.45 2 0.32 0.03 0.27 1 0.26 0.03 0.22 0.5 0.22 0.03 0.2 0.25 0.19 0.03 0.18 table 46-59. sam4cm32 typical sleep mode current consumption versus frequency master clock (mhz) idd_in - amp1 idd_io - amp2 idd_core - amp3 unit 120 16.6 0.22 13.0 ma 100 14.0 0.22 11.0 84 11.9 0.22 9.4 64 9.2 0.22 7.2 48 7.0 0.22 5.5 32 5.8 0.22 3.9 24 4.5 0.22 3.0 12 1.6 0.03 1.5 8 1.1 0.03 1.0 4 0.69 0.03 0.58 2 0.47 0.03 0.36 1 0.36 0.03 0.25 0.5 0.31 0.03 0.19 0.25 0.23 0.03 0.12
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1132 figure 46-22. typical current consumption in sleep mode sam4cm8/16 sam4cm32 0 2 4 6 8 10 12 14 16 18 0 102030405060708090100110120 idd (ma) master clock frequency (mhz) iddio ( amp2) iddin (amp1) iddcore (amp3) 0 2 4 6 8 10 12 14 16 18 0 102030405060708090100110120 idd (ma) master clock frequency (mhz) iddio ( amp2) iddin (amp1) iddcore (amp3)
1133 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 46.7.4 active mode power consumption the current consumption configuration for active mode, i.e. core executing codes, are as folows: ? vddio = vddin = 3.3v ? vddcore = 1.2v (internal voltage regulator used) ? t a = 25 c ? sub-system 0 master clock (mck), sub-system 1 ma ster clock (cpbmck) running at various frequencies (pllb used for frequencies above 12 mh z, fast rc oscillator at 12 mhz for the 12 mhz point, and fast rc oscillator at 8 mhz divided by 1/ 2/4/8/16/32 for lower frequencies) ? all peripheral clocks deactivated ? no activity on io lines ? flash wait state (fws) in eefc_f mr adjusted versus core frequency ? current measurement as per figure 46-23 figure 46-23. measurement setup for active mode amp1 vddin vddout vddcore 3.3v amp2 vddbu sam4cm vddpll vddlcd vddio amp3
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1134 46.7.4.1 test setup 1: coremark? ? coremark on core 0 (cm4p0) running out of flash in 128-bit or 64-bit access mode with and without cache enabled. cache is enabled above 0 ws. ? sub-system 1 master clock (cpbmck) and core clock (cphclk) stopped and in reset state table 46-60. sam4cm8/16 test setup 1 current consumption clock (mhz) 128-bit flash access 64-bit flash access unit cache enabled cache disabled cache enabled cache disabled idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 21.8 0.27 18.5 24.4 2.0 21.1 21.5 0.27 18.3 21.2 1.9 17.9 ma 100 18.1 0.27 15.4 21.6 1.8 18.9 18.1 0.27 15.4 19.0 1.8 16.3 84 15.3 0.27 13.0 18.8 1.7 16.6 15.3 0.27 13.0 16.8 1.7 14.5 64 11.8 0.27 10.1 15.2 1.5 13.5 11.8 0.27 10.1 14.1 1.4 12.5 48 9.2 0.27 7.9 11.7 1.4 10.5 9.2 0.27 7.9 11.3 1.3 10.0 32 7.2 0.27 5.6 9.5 1.2 7.9 7.2 0.27 5.6 9.3 1.2 7.7 24 5.6 0.27 4.3 7.5 1.1 6.2 5.6 0.27 4.3 7.2 1.2 5.9 12 2.4 0.09 2.4 3.1 0.9 3.1 2.4 0.09 2.4 3.1 1.0 3.1 8 1.6 0.09 1.6 2.1 0.7 2.1 1.6 0.09 1.6 2.1 0.9 2.1 4 1.0 0.09 1.0 1.4 0.5 1.4 1.0 0.09 1.0 1.4 0.8 1.4 2 0.70 0.09 0.69 0.90 0.40 0.90 0.70 0.09 0.69 0.70 0.70 0.70 1 0.54 0.09 0.53 0.65 0.30 0.65 0.55 0.09 0.54 0.65 0.40 0.65 0.5 0.47 0.09 0.46 0.50 0.20 0.50 0.47 0.09 0.46 0.60 0.20 0.60 0.25 0.25 0.09 0.24 0.26 0.10 0. 25 0.25 0.09 0.24 0.36 0.10 0.25
1135 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-24. typical current consumption in active mode (test setup 1) table 46-61. sam4cm32 test setup 1 current consumption clock (mhz) 128-bit flash access 64-bit flash access unit cache enabled cache disabled cache enabled cache disabled idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 25.2 0.23 22.3 29.5 1.9 26.2 25.6 0.23 22.3 25.0 1.7 21.7 ma 100 21.5 0.23 18.8 26.5 1.8 23.8 21.5 0.23 18.8 22.4 1.7 19.7 84 18.1 0.23 15.9 23.3 1.6 20.9 18.2 0.23 16.0 19.9 1.6 17.7 64 13.9 0.23 12.3 18.5 1.5 16.8 14.5 0.23 12.8 16.6 1.5 15.0 48 10.6 0.23 9.3 14.6 1.4 13.4 10.6 0.23 9.4 13.8 1.5 12.5 32 8.1 0.22 6.4 11.3 1.1 9.7 8.6 0.23 6.9 11.3 1.3 9.6 24 6.1 0.22 4.9 8.2 1.0 7.0 6.6 0.23 5.4 8.7 1.2 7.5 12 2.5 0.02 2.5 4.1 0.8 4.1 2.4 0.02 2.5 3.7 1.1 3.6 8 2.0 0.02 2.0 2.5 0.7 2.4 2.0 0.02 2.0 2.5 1.0 2.5 4 1.3 0.02 1.3 1.7 0.5 1.6 1.3 0.02 1.3 1.7 0.9 1.7 2 0.89 0.02 0.88 1.12 0.33 1.11 0.89 0.02 0.88 1.09 0.64 1.09 1 0.69 0.02 0.68 0.83 0.23 0.81 0.69 0.02 0.68 0.67 0.34 0.66 0.5 0.61 0.02 0.59 0.66 0.13 0.65 0.61 0.02 0.59 0.66 0.17 0.65 0.25 0.31 0.02 0.30 0.32 0.04 0. 31 0.31 0.02 0.30 0.32 0.06 0.31 sam4cm8/16 sam4cm32 0 5 10 15 20 25 30 35 0 102030405060708090100110120 iddio + iddin (ma) master clock frequency (mhz) 128-bit (cache enabled) 128-bit (cache disabled) 64-bit (cache enabled) 64-bit (cache disabled) 0 5 10 15 20 25 30 35 0 102030405060708090100110120 iddio + iddin (ma) master clock frequency (mhz) 128-bit (cache enabled) 128-bit (cache disabled) 64-bit (cache enabled) 64-bit (cache disabled)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1136 46.7.4.2 test setup 2: coremark ? coremark on core 1 (cm4p1) running out of sram1 (code) / sram2 (data) ? core 0 (cm4p0) in sleep mode. table 46-62. sam4cm8/16 test setup 2 current consumption clock (mhz) sram1, sram2 unit idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 22.3 0.22 19.0 ma 100 18.7 0.22 16.0 84 15.8 0.22 13.6 64 12.1 0.22 10.5 48 9.2 0.22 7.9 32 7.1 0.22 5.5 24 5.4 0.22 4.2 12 2.1 0.01 2.1 8 1.4 0.01 1.4 4 0.78 0.01 0.77 2 0.46 0.01 0.45 1 0.29 0.01 0.28 0.5 0.21 0.01 0.2 0.25 0.13 0.01 0.12 table 46-63. sam4cm32 test setup 2 current consumption clock (mhz) sram1, sram2 unit idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 23.8 0.3 20.6 ma 100 20.0 0.3 17.3 84 16.9 0.3 14.7 64 13.0 0.3 11.3 48 9.8 0.3 8.6 32 7.6 0.3 5.9 24 5.7 0.3 4.5 12 2.3 0.09 2.3 8 1.6 0.09 1.5 4 0.86 0.09 0.84 2 0.5 0.09 0.49 1 0.32 0.09 0.31 0.5 0.24 0.09 0.23 0.25 0.15 0.09 0.14
1137 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-25. typical current consumption in active mode (test setup 2) sam4cm8/16 sam4cm32 0 5 10 15 20 25 0 102030405060708090100110120 idd (ma) master clock frequency (mhz) iddin (amp1) iddio (amp2) iddcore (amp3) 0 5 10 15 20 25 0 102030405060708090100110120 idd (ma) master clock frequency (mhz) iddin (amp1) iddio (amp2) iddcore (amp3)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1138 46.7.4.3 test setup 3: coremark ? coremark on core 0 (cm4p0) running out of flash in 128-bit or 64-bit access mode with and without cache enabled. cache is enabled above 0 ws. ? coremark on core 1 (cm4p1) running out of sram1 (code) / sram2 (data) table 46-64. sam4cm8/16 test setup 3 current consumption clock (mhz) 128-bit flash access 64-bit flash access unit cache enabled cache disabled cache enabled cache disabled idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 31.3 0.28 28.0 34.2 1.9 30.9 31.3 0.28 28.0 30.7 1.8 27.4 ma 100 26.4 0.28 23.6 29.8 1.8 27.1 26.4 0.28 23.6 27.0 1.8 24.3 84 22.4 0.28 20.1 26.3 1.7 24.0 22.4 0.28 20.1 24.1 1.7 21.8 64 17.2 0.28 15.6 21.0 1.5 19.3 17.2 0.28 15.6 19.6 1.6 18.0 48 13.1 0.28 11.8 16.6 1.4 15.3 13.1 0.28 11.8 16.0 1.6 14.7 32 9.8 0.28 8.1 12.6 1.2 10.9 9.8 0.28 8.1 12.3 1.4 10.6 24 7.4 0.28 6.2 9.5 1.1 8.3 7.4 0.28 6.2 9.4 1.3 8.1 12 3.1 0.11 3.1 4.2 0.88 4.2 3.1 0.11 3.1 4.2 1.2 4.2 8 2.1 0.11 2.1 2.8 0.78 2.8 2.1 0.11 2.1 2.8 1.0 2.8 4 1.1 0.11 1.1 1.5 0.58 1.5 1.1 0.11 1.1 1.5 0.9 1.5 2 0.63 0.11 0.61 0.82 0.40 0.81 0.63 0.11 0.61 0.82 0.66 0.81 1 0.38 0.11 0.37 0.47 0.26 0.46 0.38 0.11 0.37 0.47 0.38 0.46 0.5 0.25 0.11 0.24 0.30 0.18 0.29 0.25 0.11 0.24 0.30 0.23 0.29 0.25 0.14 0.11 0.13 0.16 0.12 0. 15 0.14 0.11 0.13 0.16 0.14 0.15
1139 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-26. typical current consumption in active mode (test setup 3) table 46-65. sam4cm32 test setup 3 current consumption clock (mhz) 128-bit flash access 64-bit flash access unit cache enabled cache disabled cache enabled cache disabled idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 35.0 0.23 31.7 38.4 2.1 35.1 34.9 0.23 31.6 33.8 1.8 30.5 ma 100 29.5 0.23 26.8 33.8 2.0 31.0 29.4 0.23 26.7 29.5 1.7 27.0 84 25.1 0.23 22.8 29.4 1.8 27.1 24.9 0.23 22.7 26.6 1.7 24.3 64 19.3 0.23 17.7 23.2 1.5 21.5 19.2 0.23 17.6 21.8 1.5 20.1 48 14.7 0.23 13.4 18.0 1.3 16.8 14.6 0.23 13.4 17.7 1.5 16.5 32 10.9 0.23 9.2 13.3 1.1 11.7 10.8 0.23 9.2 13.5 1.3 11.8 24 8.2 0.23 7.0 10.5 1.0 9.3 8.2 0.22 7.0 10.3 1.2 9.0 12 3.5 0.02 3.5 4.8 0.86 4.7 3.5 0.02 3.5 4.7 1.1 4.6 8 2.4 0.02 2.4 3.2 0.74 3.2 2.4 0.02 2.4 3.1 1.0 3.1 4 1.3 0.02 1.3 1.7 0.42 1.7 1.3 0.02 1.3 1.7 0.87 1.7 2 0.72 0.02 0.71 0.92 0.40 0.89 0.71 0.02 0.81 0.94 0.56 0.94 1 0.43 0.02 0.42 0.52 0.18 0.52 0.43 0.02 0.42 0.55 0.36 0.54 0.5 0.29 0.02 0.28 0.36 0.09 0.36 0.29 0.02 0.28 0.35 0.18 0.34 0.25 0.16 0.02 0.15 0.18 0.02 0.16 0.16 0.02 0.15 0.17 0.06 0.16 sam4cm8/16 sam4cm32 0 10 20 30 40 50 0 102030405060708090100110120 iddio + iddin (ma) master clock frequency (mhz) 128-bit (cache enabled) 128-bit (cache disabled) 64-bit (cache enabled) 64-bit (cache disabled) 0 10 20 30 40 50 0 102030405060708090100110120 iddio + iddin (ma) master clock frequency (mhz) 128-bit (cache enabled) 128-bit (cache disabled) 64-bit (cache enabled) 64-bit (cache disabled)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1140 46.7.4.4 test setup 4: dsp application (five cascaded 4t h order biquad filters) fr om arm cmsis dsp library ? application running on core 1 (cm4p1) out of sram1 (code) / sram2 (data) ? core 0 (cm4p0) in sleep mode. table 46-66. sam4cm8/16 test setup 4 current consumption clock (mhz) dsp application unit idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 21.6 0.22 18.3 ma 100 18.1 0.22 15.4 84 15.3 0.22 13.1 64 11.7 0.22 10.1 48 8.9 0.22 7.6 32 7.9 0.22 6.3 24 6.0 0.22 4.8 12 2.2 0.08 2.1 8 1.5 0.08 1.5 4 0.80 0.08 0.76 2 0.47 0.08 0.46 1 0.30 0.08 0.29 0.5 0.22 0.08 0.20 table 46-67. sam4cm32 test setup 4 current consumption clock (mhz) dsp application unit idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 23.2 0.22 20.0 ma 100 19.5 0.22 16.8 84 16.4 0.22 14.2 64 12.6 0.22 11.0 48 9.5 0.22 8.3 32 8.4 0.22 6.7 24 6.3 0.22 5.1 12 1.1 0.02 1.1 8 0.75 0.02 0.74 4 0.45 0.02 0.44 2 0.29 0.02 0.28 1 0.22 0.02 0.21 0.5 0.18 0.02 0.17
1141 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-27. typical current consumption in active mode (test setup 4) sam4cm8/16 sam4cm32 0 5 10 15 20 25 0 102030405060708090100110120 idd (ma) master clock frequency (mhz) iddin (amp1) iddio (amp2) iddcore (amp3) 0 5 10 15 20 25 0 102030405060708090100110120 idd (ma) master clock frequency (mhz) iddin (amp1) iddio (amp2) iddcore (amp3)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1142 46.7.4.5 test setup 5: dsp application (five cascaded 4t h order biquad filters) fr om arm cmsis dsp library ? application running on core 0 (cm4p0) out of flash in 128-bit access mode with and without cache enabled. cache is enabled above 0 ws. ? sub-system 1 master clock (cpbmck) and core clock (cphclk) stopped and in reset. ? vddio = vddin = 3v table 46-68. sam4cm8/16 test setup 5 current consumption clock (mhz) 128-bit flash access 64-bit flash access unit cache enabled cache disabled cache enabled cache disabled idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 23.2 0.31 19.9 26.3 2.1 23.1 23.2 0.31 19.9 21.2 1.7 18.0 ma 100 19.3 0.31 16.6 23.7 2.0 21.0 19.3 0.31 16.6 18.9 1.7 16.2 84 16.3 0.31 14.1 21.2 1.9 19.0 16.3 0.31 14.1 17.5 1.7 15.3 64 12.9 0.31 11.2 17.2 1.8 15.5 12.9 0.31 11.2 14.8 1.6 13.1 48 9.9 0.31 8.6 13.9 1.6 12.7 9.9 0.31 8.6 12.3 1.6 11.1 32 7.5 0.31 5.8 10.6 1.4 9.0 7.5 0.31 5.8 9.9 1.4 8.2 24 5.7 0.31 4.4 8.7 1.2 7.5 5.7 0.31 4.4 8.1 1.3 6.9 12 2.6 0.08 2.6 4.0 0.82 3.9 2.6 0.08 2.6 3.5 0.8 3.4 8 1.7 0.08 1.7 2.7 0.70 2.7 1.7 0.08 1.7 2.4 0.8 2.4 4 0.89 0.08 0.88 1.6 0.51 1.6 0.89 0.08 0.88 1.3 0.7 1.3 2 0.56 0.08 0.55 0.96 0.39 0.95 0.56 0.08 0.55 0.78 0.54 0.76 1 0.55 0.08 0.54 0.67 0.20 0.66 0.55 0.08 0.54 0.68 0.37 0.67
1143 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 figure 46-28. typical current consumption in active mode (test setup 5) table 46-69. sam4cm32test setup 5 current consumption clock (mhz) 128-bit flash access 64-bit flash access unit cache enabled cache disabled cache enabled cache disabled idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 26.6 0.40 23.3 29.9 2.1 26.6 26.3 0.42 23.1 24.4 1.6 21.2 ma 100 22.4 0.39 19.7 27.8 2.0 24.5 22.7 0.40 20.0 22.0 1.7 19.4 84 18.9 0.38 16.7 24.1 1.9 21.9 19.4 0.39 17.1 19.9 1.7 17.7 64 14.7 0.36 13.0 19.7 1.8 18.0 14.6 0.36 13.0 16.7 1.6 15.1 48 11.6 0.34 10.4 15.3 1.6 14.0 11.6 0.34 10.4 14.4 1.5 13.2 32 9.0 0.33 7.3 11.8 1.4 10.2 8.9 0.32 7.3 11.0 1.4 9.4 24 6.5 0.32 5.3 10.0 1.4 8.7 6.5 0.31 5.2 8.2 1.3 7.5 12 2.7 0.08 2.7 4.8 1.23 4.8 2.7 0.08 2.7 3.9 1.1 3.9 8 1.9 0.06 1.8 2.9 0.99 2.9 2.2 0.06 2.2 3.0 1.1 2.9 4 1.03 0.04 1.01 1.9 0.64 1.9 1.36 0.05 1.35 1.8 0.9 1.8 2 0.95 0.03 0.94 1.23 0.45 1.24 0.95 0.04 0.94 0.86 0.71 0.86 1 0.75 0.02 0.73 0.56 0.23 0.54 0.75 0.03 0.74 0.85 0.32 0.84 sam4c8/16 sam4c32 0 5 10 15 20 25 30 35 0 102030405060708090100110120 iddio + iddin (ma) master clock frequency (mhz) 128-bit (cache enabled) 128-bit (cache disabled) 64-bit (cache enabled) 64-bit (cache disabled) 0 5 10 15 20 25 30 35 0 102030405060708090100110120 iddio + iddin (ma) master clock frequency (mhz) 128-bit (cache enabled) 128-bit (cache disabled) 64-bit (cache enabled) 64-bit (cache disabled)
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1144 46.7.5 peripheral power consumption in active mode note: 1. note: vddio = 3.3v, v ddcore = 1.2v, t a = 25 c. table 46-70. power consumption on v ddcore (1) peripheral consumption (typical) unit pio controller 4.0 a/mhz uart0 5.4 uart1 5.4 usart[0-4] 7.7 pwm 3.9 twi 5.3 spi 5.0 timer counter (tcx) 2.7 adc 3.9 smc 4.6 slcd 0.16 aes: performing aes2 56 encryption 164 trng 6.2 icm 5.2
1145 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 47. mechanical characteristics 47.1 100-lead lqfp package figure 47-1. 100-lead lqfp package drawing this package respects the recommend ations of the nemi user group. table 47-1. device and lqfp package maximum weight sam4cm 800 mg table 47-2. lqfp package reference jedec drawing reference ms-026 jesd97 classification e3 table 47-3. lqfp package characteristics moisture sensitivity level 3
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1146 47.2 soldering profile table 47-4 gives the recommended soldering profile from j-std-020c. note: the package is certified to be backward compatible with pb/sn soldering profile. a maximum of three reflow passes is allowed per component. 47.3 packaging resources this section provides land pattern definition. refer to the following ipc standards: ? ipc-7351a and ipc-782 ( generic requirements for surface mount design and land pattern standards ) http://landpatterns. ipc.org/default.asp ? atmel green and rohs policy and package material declaration data sheet http://www.atmel.com/abo ut/quality/package.aspx table 47-4. soldering profile profile feature green package average ramp-up rate (217c to peak) 3 c/sec. max. preheat temperature 175 c 25c 180 sec. max. temperature maintained above 217c 60 sec. to 150 sec. time within 5 c of actual peak temperature 20 sec. to 40 sec. peak temperature range 260 c ramp-down rate 6 c/sec. max. time 25 c to peak temperature 8 min. max.
1147 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 48. marking all devices are marked with the atmel logo and the ordering code. additional marking is as follows: where ? ?yy?: manufactory year ? ?ww?: manufactory week ? ?v?: revision ? ?xxxxxxxxx?: lot number yyww v xxxxxxxxx arm
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1148 49. ordering information table 49-1. ordering codes for sam4cm devices ordering code mrl flash (kbytes) package conditioning package type temperature operating range atsam4cmp32ca-au a 2 x 1024 lqfp100 tray green industrial (-40c to +85c atsam4cmp32ca-aur reel atsam4cmp16cb-au b 1024 tray atsam4cmp16cb-aur reel atsam4cmp8cb-au 512 tray atsam4cmp8cb-aur reel atsam4cms32ca-au a 2 x 1024 tray atsam4cms32ca-aur reel atsam4cms16cb-au b 1024 tray atsam4cms16cb-aur reel atsam4cms8cb-au 512 tray atsam4cms8cb-aur reel atsam4cmp16ca-au a 1024 lqfp100 tray green industrial (-40c to +85c) atsam4cmp16ca-aur reel atsam4cmp8ca-au 512 tray atsam4cmp8ca-aur reel atsam4cms16ca-au 1024 tray atsam4cms16ca-aur reel atsam4cms8ca-au 512 tray atsam4cms8ca-aur reel
1149 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 50. sam4cm16/8 errata revi sion a (mrl a) parts 50.1 device identification this section refers to devices: table 50-1. device list for errata device marking chip id atsam4cmp16ca-au 0xa64c_0ce0 atsam4cmp16ca-aur 0xa64c_0ce0 atsam4cmp8ca-au 0xa64c_0ae0 atsam4cmp8ca-aur 0xa64c_0ae0 atsam4cms16ca-au 0xa64c_0ce0 atsam4cms16ca-aur 0xa64c_0ce0 atsam4cms8ca-au 0xa64c_0ae0 atsam4cms8ca-aur 0xa64c_0ae0
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1150 50.2 flash memory 50.2.1 flash: incorrect flash read may occur depending on vddio voltage and flash wait state flash read issues leading to wrong instruction fetch or data read may occur under the following operating condition: ? vddio < 2.4v and flash wait state (1) 1 if the core clock frequency does not re quire the use of the flash wait state (2) (fws = 0 in eefc_fmr), there are no constraints on vddio voltage. the usable voltage range for vddio is defined in the table ?recommended operating conditions on power supply inputs? in the section ?electri cal characteristics?. notes: 1. fws field in eefc_fmr register. 2. see the table ?flash wait state versus operating freque ncy? in the section ?electrical characteristics? for maximum core clock frequency at zero (0) wait states. problem fix/workaround none. the issue is corrected in the device revision marketing revision level b (mrl b). please contact your local sales representative for further details. 50.3 supply controller (supc) 50.3.1 supc: supply monitor (sm) on vddio the supply monitor (sm) sampling mode reducing the avera ge current consumption on vddio is not functional. problem fix/workaround use the supply monitor in continuous mode only. 50.3.2 supc: core voltage regulator standby mode control the core voltage regulator standby mode controlled by the onreg bit in supc_mr is not functional. this does not prevent to power vddcore and vddpl by using an external voltage regulator. problem fix/workaround none. do not use the onreg bit. 50.3.3 supc: core brownout detector. unpredictable beha vior if bod is disabled, vddcore is lost and vddio is powered in active mode or in wait mode, if the brownout dete ctor (bod) is disabled (supc_mr: boddis=1) and power is lost on vddcore while vddio is powered, the device can be reset incorrectly and its behavior becomes then unpredictable. problem fix/workaround when the brownout detector is disabled in active or in wait mode, vddcore must be always powered.
1151 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 50.4 parallel input outp ut (pio) controller 50.4.1 pio: schmitt trigger ? schmitt triggers on all pio controllers are not enabled by default (after reset) as stated in the product datasheet. ? enable and disable values in the pio schmitt trigger register (for all pio cont rollers) are inverted. the definition of pio_schmitt fields must be as follows: ? 0: schmitt trigger is disabled. ? 1: schmitt trigger is enabled. problem fix/workaround none. it is up to the application to enable schmitt trigger mode and to take into account the inverted values of the pio_schmitt fields. 50.5 watchdog (wdt) / reinfor ced safety watchdog (rswdt) 50.5.1 wdt / rswdt not stopped in wait mode when the watchdog (wdt) or the reinforced safety wa tchdog (rswdt) is enabled and the waitmode bit set to 1 is used to enter low-power wait mo de, the wdt/rswdt is not halted. if the time spent in wait mode is longer than the watchdog (reinforced safety watchdog) time-out , the device is reset provided that the wdt/rswdt reset is enabled. problem fix/workaround when entering wait mode, the wait-for-event (wfe) inst ruction of the cortex-m4 processor must be used while the sleepdeep bit of the cort ex-m system control regist er (scb_scr) is set to 0. 50.5.2 rswdt windowing mode when the rswdt is configured in windowing mode (wdd set lo wer than wdv in rswdt_mr), an unexpected watchdog reset order may be sent to the reset controller (rstc). problem fix/workaround do not use the windowing mode of the rswd t and set wdd to 4095 in rswdt_mr.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1152 50.6 enhanced embedded fl ash controller (eefc) 50.6.1 eefc: erase sector (es) command cannot be performed if a subsector is locked (only in flash sector 0) if one of the subsectors ? small sector 0 ? small sector 1 ? larger sector is locked within the flash sector 0, the erase sector (es) command cannot be processed on non-locked subsectors. refer to the flash overview in the ?memories? section of the datasheet. fix/workaround all the lock bits of the sector 0 must be cleared prio r to issuing the es command. after the es command has been issued, the lock bits must be reverted to the state before clearing them. 50.7 wait for interrupt (wfi) 50.7.1 unpredictable software behavior when entering sleep mode when entering sleep mode, if an interru pt occurs during wfi or wfe instruction (with pmc_fsmr.lpm=0) , the arm core may read a wrong data, thus leading to unpredict able behavior of the software. this issue is not present in wait mode. fix/workaround the slave interface for the flash must be set to no default master in th e bus matrix controller. this is done by setting the field defmstr_type in the register matrix_scfg to no_default. matrix_scfg[2] = matrix_scfg.slot_cycle(0x1ff) | matrix_scfg.defmstr_type(0x0); this operation must be done once in the so ftware or the instruction before wfi or wfe. 50.8 power supply and powe r control / clock system 50.8.1 core 1 systick counter erratic behavior if the core 0 processor clock (hclk) frequency is highe r than four times the frequency of the core 1 processor clock (cphclk), the systick counter behavior is erratic. fix/workaround always ensure that f hclk < 4 x f cphclk . 50.9 power management controller (pmc) 50.9.1 srcb bit in ckgr_pllb register the srcb bit is programmed in bit 29 of the ckgr_pllb re gister but must be read in bit 27 of this register. fix/workaround for srcb, read bit 27 of the ckgr_pllb register.
1153 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 51. sam4cm16/8 errata revi sion b (mrl b) parts 51.1 device identification this section refers to devices: 51.2 supply controller (supc) 51.2.1 supc: supply monitor (sm) on vddio the supply monitor (sm) sampling mode reducing the avera ge current consumption on vddio is not functional. problem fix/workaround use the supply monitor in continuous mode only. 51.2.2 supc: core voltage regulator standby mode control the core voltage regulator standby mode controlled by the onreg bit in supc_mr is not functional. this does not prevent to power vddcore and vddpl by using an external voltage regulator. problem fix/workaround none. do not use the onreg bit. 51.2.3 supc: core brownout detector. unpredictable beha vior if bod is disabled, vddcore is lost and vddio is powered in active mode or in wait mode, if the brownout dete ctor (bod) is disabled (supc_mr: boddis=1) and power is lost on vddcore while vddio is powered, the device can be reset incorrectly and its behavior becomes then unpredictable. problem fix/workaround when the brownout detector is disabled in active or in wait mode, vddcore must be always powered. table 51-1. device list for errata device marking chip id atsam4cmp16cb-au 0xa64c_0ce1 atsam4cmp16cb-aur 0xa64c_0ce1 atsam4cmp8cb-au 0xa64c_0ae1 atsam4cmp8cb-aur 0xa64c_0ae1 atsam4cms16cb-au 0xa64c_0ce1 atsam4cms16cb-aur 0xa64c_0ce1 atsam4cms8cb-au 0xa64c_0ae1 atsam4cms8cb-aur 0xa64c_0ae1
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1154 51.3 parallel input outp ut (pio) controller 51.3.1 pio: schmitt trigger ? schmitt triggers on all pio controllers are not enabled by default (after reset) as stated in the product datasheet ? enable and disable values in the pio schmitt trigger register (for all pio cont rollers) are inverted. the definition of pio_schmitt fields must be as follows: ? 0: schmitt trigger is disabled. ? 1: schmitt trigger is enabled. problem fix/workaround none. it is up to the application to enable schmitt trigger mode and to take into account the inverted values of the pio_schmitt fields. 51.4 watchdog (wdt) / reinfor ced safety watchdog (rswdt) 51.4.1 wdt / rswdt not stopped in wait mode when the watchdog (wdt) or the reinforced safety wa tchdog (rswdt) is enabled and the waitmode bit set to 1 is used to enter low-power wait mo de, the wdt/rswdt is not halted. if the time spent in wait mode is longer than the watchdog (reinforced safety watchdog) time-out , the device is reset provided that the wdt/rswdt reset is enabled. problem fix/workaround when entering wait mode, the waitforevent (wfe) instruction of the cortex-m4 processor must be used while the sleepdeep bit of the cort ex-m system control regist er (scb_scr) is set to 0. 51.4.2 rswdt windowing mode when the rswdt is configured in windowing mode (wdd set lo wer than wdv in rswdt_mr), an unexpected watchdog reset order may be sent to the reset controller (rstc). problem fix/workaround do not use the windowing mode of the rswd t and set wdd to 4095 in rswdt_mr.
1155 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 51.5 enhanced embedded fl ash controller (eefc) 51.5.1 eefc: erase sector (es) command cannot be performed if a subsector is locked (only in flash sector 0) if one of the subsectors ? small sector 0 ? small sector 1 ? larger sector is locked within the flash sector 0, the erase sector (es) command cannot be processed on non-locked subsectors. refer to the flash overview in the ?memories? section of the datasheet. fix/workaround all the lock bits of the sector 0 must be cleared prio r to issuing the es command. after the es command has been issued, the lock bits must be reverted to the state before clearing them. 51.6 wait for interrupt (wfi) 51.6.1 unpredictable software behavior when entering sleep mode when entering sleep mode, if an interru pt occurs during wfi or wfe instruction (with pmc_fsmr.lpm=0) , the arm core may read a wrong data, thus leading to unpredict able behavior of the software. this issue is not present in wait mode. fix/workaround the slave interface for the flash must be set to no default master in th e bus matrix controller. this is done by setting the field defmstr_type in the register matrix_scfg to no_default. matrix_scfg[2] = matrix_scfg.slot_cycle(0x1ff) | matrix_scfg.defmstr_type(0x0); this operation must be done once in the so ftware or the instruction before wfi or wfe. 51.7 power supply and powe r control / clock system 51.7.1 core 1 systick counter erratic behavior if the core 0 processor clock (hclk) frequency is highe r than four times the frequency of the core 1 processor clock (cphclk), the systick counter behavior is erratic. fix/workaround always ensure that f hclk < 4 x f cphclk . 51.8 power management controller (pmc) 51.8.1 srcb bit in ckgr_pllb register the srcb bit is programmed in bit 29 of the ckgr_pllb re gister but must be read in bit 27 of this register. fix/workaround for srcb, read bit 27 of the ckgr_pllb register.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1156 52. sam4cm32 errata revision a (mrl a) parts 52.1 device identification this section refers to devices: 52.2 supply controller (supc) 52.2.1 supc: supply monitor (sm) on vddio the supply monitor (sm) sampling mode reducing the avera ge current consumption on vddio is not functional. problem fix/workaround use the supply monitor in continuous mode only. 52.2.2 supc: core voltage regulator standby mode control the core voltage regulator standby mode controlled by the onreg bit in supc_mr is not functional. this does not prevent to power vddcore and vddpl by using an external voltage regulator. problem fix/workaround none. do not use the onreg bit. 52.2.3 supc: core brownout detector. unpredictable beha vior if bod is disabled, vddcore is lost and vddio is powered in active mode or in wait mode, if the brownout dete ctor (bod) is disabled (supc_mr: boddis=1) and power is lost on vddcore while vddio is powered, the device can be reset incorrectly and its behavior becomes then unpredictable. problem fix/workaround when the brownout detector is disabled in active or in wait mode, vddcore must be always powered. table 52-1. device list for errata device marking chip id atsam4cmp32ca-au 0xa64d_0ee0 atsam4cmp32ca-aur 0xa64d_0ee0
1157 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 52.3 parallel input outp ut (pio) controller 52.3.1 pio: schmitt trigger ? schmitt triggers on all pio controllers are not enabled by default (after reset) as stated in the product datasheet ? enable and disable values in the pio schmitt trigger register (for all pio cont rollers) are inverted. the definition of pio_schmitt fields must be as follows: ? 0: schmitt trigger is disabled. ? 1: schmitt trigger is enabled. problem fix/workaround none. it is up to the application to enable schmitt trigger mode and to take into account the inverted values of the pio_schmitt fields. 52.4 reinforced safety watchdog (rswdt) 52.4.1 rswdt windowing mode when the rswdt is configured in windowing mode (wdd set lo wer than wdv in rswdt_mr), an unexpected watchdog reset order may be sent to the reset controller (rstc). problem fix/workaround do not use the windowing mode of the rswd t and set wdd to 4095 in rswdt_mr. 52.5 enhanced embedded fl ash controller (eefc) 52.5.1 eefc: erase sector (es) command cannot be performed if a subsector is locked (only in flash sector 0) if one of the subsectors ? small sector 0 ? small sector 1 ? larger sector is locked within the flash sector 0, the erase sector (es) command cannot be processed on non-locked subsectors. refer to the flash overview in the ?memories? section of the datasheet. fix/workaround all the lock bits of the sector 0 must be cleared prio r to issuing the es command. after the es command has been issued, the lock bits must be reverted to the state before clearing them.
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1158 52.6 wait for interrupt (wfi) 52.6.1 unpredictable software behavior when entering sleep mode when entering sleep mode, if an interru pt occurs during wfi or wfe instruction (with pmc_fsmr.lpm=0) , the arm core may read a wrong data, thus leading to unpredict able behavior of the software. this issue is not present in wait mode. fix/workaround the slave interface for the flash must be set to no default master in th e bus matrix controller. this is done by setting the field defmstr_type in the register matrix_scfg to no_default. matrix_scfg[2] = matrix_scfg.slot_cycle(0x1ff) | matrix_scfg.defmstr_type(0x0); this operation must be done once in the so ftware or the instruction before wfi or wfe. 52.7 power management controller (pmc) 52.7.1 srcb bit in ckgr_pllb register the srcb bit is programmed in bit 29 of the ckgr_pllb re gister but must be read in bit 27 of this register. fix/workaround for srcb, read bit 27 of the ckgr_pllb register.
1159 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 53. revision history in the tables that follow, the most rece nt version of the document appears first. table 53-1. sam4cm datasheet rev. 11203c revision history doc. rev. 11203c changes 06-oct-14 added sam4cmp32c and sam4cms32c devices. modificati ons throughout datasheet for these devices. ?features? in section ?safety? , modified information on anti-tamper detection i/os. section 1. ?confi guration summary? added sam4cmp32c and sam4cms32c devices. section 2. ?block diagram? figure 2-1 ?sam4cm series 100-pin block diagram? : added traceswo to tdo pin.added wkup[0:13]. moved dual watchdog block out of backup zone. added power supply for segment lcd controller. section 3. ?signal description? table 3-1 ?signal description list? : added section with supply controller signals, including wkup0 and wkup[1:13]. removed adtrg signal. removed pgmck signal. section 5. ?power supply and power control? updated table 5-1 ?power supply voltage ranges? . modified section 5.1.2 ?lcd voltage regulator? . modified section 5.1.3 ?autom atic power switch? . modified section 5.1.5 ?typical powering schematics? .. removed note (2) on emafe following figure 5-2 ?single supply operation? . modified section 5.1.5.3 ?single power supp ly using one main battery and lcd controller in backup mode? . updated section 5.3.2 ?device configuration after a power cycle when booting from flash memory? and section 5.3.3 ?device configuration after a reset? . modified note in section 5.5 ?low-power modes? . added step 8 to section 5.5.1.1 ?entering and exiting backup mode? . table 5-2 ?low-power mode configuration summary? : removed column current consumption and updated notes below. section 6. ?input/output lines? changed section 6.3 title from ?test pin? to ?tst pin? . section 6.7 ?shutdown (shdn) pin? : removed sentence on shdn pin controlli ng an external voltage regulator and/or power switch. updated section 6.9 ?erase pin? . section 7. ?product mapping and peripheral access? added figure 7-3 ?sam4cm32 memory mappi ng of code and sram area? and figure 7-5 ?sam4cm32 memory mapping of the peripherals area? . updated figure 7-6 ?sam4cm32/16/8 memory mapping of external sram and external devices area? .
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1160 06-oct-14 section 8. ?memories? updated section 8.1.1 ?internal sram? . added dual-plane feature in section 8.1.4 ?embedded flash? , changed figure 8-1 ?dual bank and dual boot firmware upgrade? . added table 8-1 ?sam4cm flash size? . updated section 8.1.4.5 ?security bit? . updated table 8-2 ?lock bit number? . updated section 8.1.4.10 ?gpnvm bits? and table 8-3 ?general-purpose nonvolatile memory bits? . added section 8.1.5.4 ?sub-system 1 start-up time? . . removed section 8.2.1 ?stati c memory controller? from section 8.2 ?external memories? section 10. ?system controller? updated section 10.2.4 ?supply monitor on vddio? . updated section 10.3 ?reset controller? . section 11. ?peripherals? table 11-1 ?peripheral identifiers? : modified wdt (id 4). table 11-4 ?i/o line features abbreviations? : removed medium drive. added maximum drive. table 11-5 ?multiplexing on pio controller a (pioa)? , table 11-6 ?multiplexing on pio controller b (piob)? , table 11-7 ?multiplexing on pio controller c (pioc)? : modified features column in all tables for all i/o lines. section 12. ?arm cortex-m4 processor? corrected instruction in section 12.5.3 ?power management programming hints? . updated table 12-5 ?memory region shareability policies? . updated table 12-11 ?faults? . updated table 12-41 ?memory protection unit (mpu) register mapping? with new register names for mpu_rasr_ax and mpu_rbsr_ax. updated table 12-31 ?mapping of interrupts to the interrupt variables? . section 12.9.1.13 ?configurable fault status register? : added lsperr bit. section 14. ?boot program? section 14.5.3 ?in applicatio n programming (iap) feature? : corrected mc_fsr to eefc_fsr. section 15. ?reset controller (rstc)? section 15.4.1 ?reset controller overview? : changed events that that trigger asse rtion of reset signals by the rstc. changed vdd_reg_bu to vddbu. removed section ?brownout manager?. section 15.4.3.2 ?backup reset? : replaced ?core_backup_reset? with ?vddcore_nreset?. section 15.5.1 ?reset controller control register? : modified extrst description. section 15.5.2 ?reset co ntroller status register? : modified bit descriptions. section 15.5.3 ?reset co ntroller mode register? : modified erstl bit description. section 16. ?real- time timer (rtt)? modified section 16.4 ?functional description? . section 16.5.1 ?real-time timer mode register? : modified rtpres description. section 16.5.2 ?real-time timer alarm register? : modified almv description. section 16.5.3 ?real-time timer value register? : added notes. table 53-1. sam4cm datasheet rev. 1 120 3c revision history (continued) doc. rev. 11203c changes
1161 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 06-oct-14 section 17. ?real- time clock (rtc)? section 17.5.7 ?rtc a ccurate clock calibration? ; modified paragraph on calibration circuitry. added paragraph on clock calibration correction. section 17.6.2 ?rtc mode register? : modified descriptions of ne gppm, highppm and thigh bits. added section 17.6.17 ?rtc write protection mode register? . section 18. ?watchdog timer (wdt)? modified figure 18-2 ?watchdog behavior? . section 19. ?reinforced safety watchdog timer (rswdt)? added windowed watchdog in section 19.2 ?embedded characteristics? and section 19.4 ?functional description? . modified figure 19-2 ?watchdog behavior? . section 19.5.2 ?reinforced safety watchdog timer mode register? : added notes. section 20. ?supply controller (supc)? section 20.4.2 ?slow clock generator? : updated information on entering bypass mode using oscbypass and xtsalsel bits. section 20.4.4 ?segmented lcd voltage regulator control? : changed the section name a nd aligned references to slcd and slcd controller in the text. updated content. section 20.4.6 ?supply monitor? : supply monitor sampling mode, power reduction factor: replaced incorrect values of 32, 256 or 2048 by the correct values of 2, 16 and 128. figure 20-4 ?sam4cm16/8 wake-up sources? : modified to show that wake-up input detectors are based on edges. added figure 20-5 ?sam4cm32 wake-up sources? . section 20.4.9.1 ?force wake-up? : corrected bit name from fwup to fwups in 2nd paragraph. section 20.4.9.2 ?wake-up inputs? : corrected polarity bit name from wkuppl to wkupt. section 20.4.9.3 ?low-power debounc er inputs (tamper detection pins)? : added information on sam4cm32 devices. corrected register names for wkuptx bits and lpdbcclr bit. section 20.6.5 ?supply controller mode register? : changed oscbypass bit description. section 20.6.8 ?supply controller status register? : updated to bit descriptions as ?cleared on read? where applicable. updated the bit description for wkupis = 1 section 22. ?enhanced embedded flash controller (eefc)? number of gpnvm bits changed to 3 for sam4c32. added informaton on dual-plane configuration available for sam4c32. section 27. ?static memo ry controller (smc)? section 27.2 ?embedded characteristics? : added bullet for byte write or byte select lines table 27-1 ?i/o line description? : updated with latch enables table 27-2 ?static memory contro ller (smc) multiplexed signals? : completed table with relevant information. added text and figures for 16-bit memory connections in section 27.6 ?external memory mapping? , section 27.7.1 ?data bus width? , section 27.7.2 ?byte write or byte select access? , section 27.9 ?standard read and write protocols? and section 27.10 ?scrambling/unscrambling function? . table 27-5 ?reset values of timing parameters? : modified reset values. section 27.16.4 ?smc mode register? : added bat bit. table 53-1. sam4cm datasheet rev. 1 1203c revision history (continued) doc. rev. 11203c changes
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1162 06-oct-14 section 29. ?clock generator? section 29.2 ?embedded characteristics? : removed ?write protected regsiters?. figure 29-1 ?clock generator block diagram? and figure 29-4 ?dividers and pll block diagram? updated for clarity. added section 29.5.5 ?bypassing th e main crystal oscillator? . added section 29.5.6 ?switching main clock between t he main rc oscillator and fast crystal oscillator? . section 29.6.1 ?divider and phase lock loop programming? : introduced the notion that the us er must wait for a delay of two slck clock cycles between the disable command and the actu al disable of the pll. removed ?lock? from step 4. section 30. ?power management controller (pmc)? updated section 30.2 ?embedded characteristics? . figure 30-1 ?general clock block diagram? : updated for clarity, relocate on/off switch for usb and pck.. section 30.10 ?main processor fast startup? : updated for clarity. added section 30.11 ?main processor startup from embedded flash? . section 30.13 ?main clock failure detector? : updated for clarity. section 30.14 ?slow crystal clock frequency monitor? : added ?the sel4/sel8/sel12 bits of pmc_ocr must be cleared?. section 30.15 ?programming sequence? : updated for clarity. section 30.18 ?power management c ontroller (pmc) user interface? : corrected pmc_ sr reset value. section 30.18.7 ?pmc clock genera tor main oscillator register? : added note to moscxtby bit description. section 30.18.8 ?pmc clock generator main clock frequency register? : updated mainf and mainfrdy bit descriptions. section 30.18.9 ?pmc clock generator plla register? : updated mula bit description. section 30.18.10 ?pmc clock generator pllb register? : changed srcb bit description. changed mulb bit description. section 31. ?chip identifier (chipid)? table 31-1 ?sam4cm chip id registers? : updated with new devices. section 31.3.1 ?chip id register? : ?nvpsiz: nonvolatile program memory size? : changed information in row for value 8. changed ?arch: architecture identifier? bit information. section 32. ?parallel input/output (pio3) controller? ?pio clock? and ?pio controller clock? replaced by ?peripheral clock? throughout. ?mck? and ?mck? replaced by ?peripheral clock? throughout. removed section ?external interrupt lines?. updated figure 32-2 ?i/o line control logic? . section 32.5.1 ?pull-up and pull-down resistor control? : added information on setting pull-up and pull-down. section 32.5.3 ?peripheral a or b or c or d selection? : added information on products that do not have a, b, c and d peripherals. section 32.5.11 ?programmable i/o drive? : corrected list of configurable pads. section 32.6.38 ?pio additional interrupt modes mask register? : updated bit description. modified section 32.6.48 ?pio i/o drive register? (was pio i/o drive register 1). removed section ?pio i/ o drive register 2?. updated table 32-3 ?register mapping? for drive registers changes. table 53-1. sam4cm datasheet rev. 1 1203c revision history (continued) doc. rev. 11203c changes
1163 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 06-oct-14 section 33. ?serial peri pheral interface (spi)? ?mck? replaced by ?peripheral clock? throughout. section 33.2 ?embedded characteristics? : reworked list. reworked figure 33-1 ?block diagram? , figure 33-3 ?spi transfer format (ncpha = 1, 8 bits per transfer)? and figure 33-4 ?spi transfer format (ncpha = 0, 8 bits per transfer)? . modified section 33.7.3 ?master mode operations? . section 33.7.3.6 ?spi periph eral dma controller (pdc)? , section ?transfer size? : under ?fixed mode? replaced ?8-bit to 16-bit data? with ?9-b it to 16-bit data?. section 33.8.2 ?spi mode register? : modified dlybcs bit description. section 33.8.9 ?spi chip select register? : added register addresses. updat ed csnaat bit description. updated descriptions of bits scbr, dlybs, and dlybct. section 34. ?two-wire interface (twi2)? ?mck? replaced by ?peripheral clock? throughout. table 34-1 ?atmel twi compatibility with i2c standard? : clock synchronization added as supported feature. section 34.7.3.3 ?programming master mode? : added note after section. removed references to twihs. section 34.7.3.7 ?using the peripheral dma controller (pdc)? : modified ?data transmit with the pdc? and ?data receive with the pdc? . ?clock synchronization in write mode? : at end of last sentence, changed ?in read mode? to ?in write mode?. section 34.7.3.5 ?master receiver mode? : removed reference to clock stretching in the ?warning?. (clock stretching is a slave-only mechanism) figure 34-11 ?master read wait state with multiple data bytes? : changed title and figure to remove references to clock stretching reference (slave-only mechanism) section 34.7.5.4 ?receiving data? : removed reference to twi_thr. ?clock stretching sequence? : added section which refers only to twi_thr. ?clock synchronization/stretching? changed the section name and updated. section 35. ?universal asynchronous receiver transmitter (uart)? ?mck? replaced by ?peripheral clock? throughout. table 53-1. sam4cm datasheet rev. 1 1203c revision history (continued) doc. rev. 11203c changes
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1164 06-oct-14 section 36. ?universal synchronous asynchronous receiver transmitter (usart)? ?mck? replaced by ?peripheral clock? throughout. section 36.2 ?embedded characteristics? : added ?digital filter on receive line? bullet updated figure 36-1 ?usart block diagram? . removed table ?spi operating mode?. section 36.6.1 ?baud rate generator? : updated 4th paragraph and figure. updated information on rxidlev bit in section 36.6.3.2 ?m anchester encoder? and section 36.7.21 ?usart manchester configuration register? . updated figure 36-36 ?example of rts drive with timeguard? . table 36-7 ?possible values for the fi/di ratio? : in top row, replaced ?774? with ?744?. section ?transmit character repetition? : updated 3rd paragraph. section ?disable successive receive nack? : updated last sentence. section 36.6.7.5 ?character transmission? : inack replaced by wrdbt. table 36-14 ?register mapping? : us_man reset value corrected to 0x30011004. section 36.7.3 ?usart mode register? : updated usart_mode, usclks and par field descriptions. added note on max_iteration field to dsnack bit description. section 36.7.4 ?usart mo de register (spi_mode)? : deleted chmode filed description and added clko bit. updated endrx, endtx, txbufe, and rxbuff bit descriptions in section 36.7.5 ?usart interrupt enable register? , section 36.7.6 ?usart interrupt enable register (spi_mode)? , section 36.7.7 ?usart interrupt disable register? , section 36.7.9 ?usart in terrupt mask register? and section 36.7.11 ?usart channel status register? . updated rxrdy, txrdy, txempty, iter and ctsic bit descriptions in section 36.7.11 ?usart channel status register? . updated rxrdy, txrdy, and txempty bit descriptions in section 36.7.12 ?usart channel status register (spi_mode)? section 36.7.18 ?usart fi di ratio register? : fi_di_ratio field now 11 bits wide and updated description. section 37. ?timer counter (tc)? ?mck? replaced by ?peripheral clock? throughout. added section 37.6.14.6 ?missing pulse detection and auto-correction? . section 37.7.14 ?tc block mode register? : removed filter bit (register bit 19 now reserved). added autoc bit and maxcmp field. section 37.7.18 ?tc qdec interrupt status register? : added mpe bit. section 39. ?segment liquid crystal display controller (slcdc)? ?sclk? replaced by ?slck? throughout. updated section 39.5.2 ?power management? . in section 39.5 ?product dependencies? , removed section ?number of segments and commons?. revised section 39.6.7 ?disabling the slcdc? (was ?disable sequence?). section 39.8.8 ?slcdc interrupt mask register? : modified access to read-only. updated dis bit descriptions. table 53-1. sam4cm datasheet rev. 1 1203c revision history (continued) doc. rev. 11203c changes
1165 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 06-oct-14 section 40. ?analog-to-digital converter (adc)? replaced references to ?mck? with ?peripheral clock? in text and figures. section 40.1 ?description? ?: corrected name of register for onref and forceref bits from adc_sr to adc_isr. figure 40-1 ?analog-to-digital converter block diagram? : added bus clock. added adc clock output from control logic block. added table 40-2 ?peripheral ids? and table 40-3 ?i/o lines? . renamed figure 40-4 from govre and ovrex flag behavior to ?eocx, govre and ovrex flag behavior? . corrected adc_sr to adc_isr in figure 40-3 ?eocx and drdy flag behavior? and figure 40-4 ?eocx, govre and ovrex flag behavior? . modified warning below figure 40-4 ?eocx, govre and ovrex flag behavior? . section 40.6.6 ?sleep mode and conversion sequencer? : removed description of adc channel use on an application board (3 paragraphs). in figure 40-6 ?non-optimized temperature conversion? to figure 40-11 ?digital averaging function waveforms on single trigger event, non-interleaved? : added note on adc_sel. section 40.7.5 ?adc channel disable register? : modified warning below bit description. section 40.7.11 ?adc interrupt status register? : updated all bit descriptions with information on status. corrected compe bit name and description; changed ?error? to ?e vent?. modified endrx and rxbuff bit descriptions. added addresses for all registers. section 42. ?advanced encryption standard (aes)? updated section 42.4.4.3 ?if aes_mr.lod = 1? updated figure 42-4 ?pdc transfer with aes_mr.lod = 1? . updated section 42.4.5 ?galois/counter mode (gcm)? . section 42.5.2 ?aes mode register? : updated procdly bit description. section 42.5.3 ?aes inte rrupt enable register? , section 42.5.4 ?aes inte rrupt disable register? , section 42.5.5 ?aes interrupt mask register? , section 42.5.6 ?aes inte rrupt status register? : added tagrdy bit. section 43. ?integrity check monitor (icm)? updated section 43.1 ?description? . renamed figure 43-1 ?four-region monitoring example? (was ?integrity check monito r integrated in the system?). inserted table 43-1 ?peripheral ids? . section 43.5.1.2 ?icm region configuration structure member? : corrected configuration value descriptions for bits rhien, dmien, beien, wcien, ecien and suien. table 53-1. sam4cm datasheet rev. 1 1203c revision history (continued) doc. rev. 11203c changes
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1166 06-oct-14 section 46. ?electri cal characteristics? table 46-2 ?recommended operating conditions on power supply inputs? : changed min value of vddlcd. modified column ?conditions? for all paramete rs. added notes at end of table. updated r ja and p d in table 46-4 ?recommended thermal operating conditions? . table 46-7 ?input characteristics? : added mention of voltage reference to vddio in paragraph preceding table. updated table 46-8 ?spi timings? . updated table 46-9 ?smc read signals - nrd controlled (read_mode = 1)? , table 46-10 ?smc read signals - ncs controlled (read_mode= 0)? , table 46-11 ?smc write signals - nwe controlled (write_mode = 1)? and table 46- 12 ?smc write ncs controlled (write_mode = 0)? . updated table 46-13 ?usart spi timings? . in table 46-18 ?lcd buffers characteristics? , changed max value for z out ?buffer output impedance?. changed convergence value and max value for t r / t f ?rising or falling time?. table 46-21 ?vddio supply monitor? : added note (2). removed figure ?vddio supply monitor?. improved definition of parameters and modified equations and figures in section 46.5.11 ?32.768 khz crystal oscillator? and section 46.5.12 ?3 to 20 mhz crystal oscillator? . table 46-27 ?32.768 khz crystal oscillator characteristics? : modified min/typ/max values for clext. table 46-33 ?temperature sensor characteristics? : modified condition of parameter v t settling time. table 46-35 ?adc power supply characteristics? : modified typ for supply voltage range (vddin). table 46-36 ?adc voltage reference i nput characteristics (advref pin)? : modified min value of v advref table 46-41 ?programmable voltage reference characteristics? : modified condition for v advref table 46-45 ?current or voltage measurem ent channel electrical characteristics? : modified max value i ddon when off added section 46.6.2.2 ?sam4cm32 flash wa it states and operating frequency? . added table 46-53 ?sam4cm32 typical current consumption values for backup mode configurations a and b? and figure 46-17 ?typical current consumption in backup mode for configurations a and b? . modified table 46-54 ?sam4cm8/16 typical current consumpti on values for backup mode configurations c and d? . added table 46-55 ?sam4cm32 typical current consumption values for backup mode configurations c and d? and figure 46-19 ?typical current consumption in backup mode for configurations c and d? . updated section 46.7.2.1 ?wait mode configuration? . updated table 46-56 ?sam4cm8/16 typical cu rrent consumption in wait mode? . added table 46-57 ?sam4cm32 typical current consumption in wait mode? . section 46.7.3 ?sleep mode current consumption? : modified information on sub-system frequencies in bullets. updated table 46-58 ?sam4cm8/16 typical sleep mo de current consumption versus frequency? . added table 46-59 ?sam4cm32 typical sleep mode current consumption versus frequency? . added figure 46-22 ?typical current consumption in sleep mode? . section 46.7.4 ?active mode power consumption? : modified information on sub-system frequencies in bullets. updated table 46-60 ?sam4cm8/16 test setup 1 current consumption? . added table 46-61 ?sam4cm32 test setup 1 current consumption? and figure 46-24 ?typical current consumption in active mode (test setup 1)? . updated table 46-62 ?sam4cm8/16 test setup 2 current consumption? . added table 46-63 ?sam4cm32 test setup 2 current consumption? and figure 46-25 ?typical current consumption in active mode (test setup 2)? . updated table 46-64 ?sam4cm8/16 test setup 3 current consumption? . added table 46-65 ?sam4cm32 test setup 3 current consumption? and figure 46-26 ?typical current consumption in active mode (test setup 3)? . updated table 46-66 ?sam4cm8/16 test setup 4 current consumption? . added table 46-67 ?sam4cm32 test setup 4 current consumption? and figure 46-27 ?typical current consumption in active mode (test setup 4)? . updated table 46-68 ?sam4cm8/16 test setup 5 current consumption? . added table 46-69 ?sam4cm32test setup 5 current consumption? and figure 46-28 ?typical current consumpt ion in active mode (test setup 5)? . table 53-1. sam4cm datasheet rev. 1 1203c revision history (continued) doc. rev. 11203c changes
1167 sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 06-oct-14 section 49. ?ordering information? updated table 49-1 ?ordering codes for sam4cm devices? . section 50. ?sam4cm16/8 errata revision a (mrl a) parts? removed erratum on supc: lcd end of frame disable does not work. added section 50.5.2 ?rswdt windowing mode? , section 50.7.1 ?unpredictable software behavior when entering sleep mode? , section 50.8.1 ?core 1 systick counter erratic behavior? and section 50.9.1 ?srcb bit in ckgr_pllb register? . added section 51. ?sam4cm16/8 errata revision b (mrl b) parts? . added section 52. ?sam4cm32 errata revision a (mrl a) parts? . table 53-1. sam4cm datasheet rev. 1 1203c revision history (continued) doc. rev. 11203c changes table 53-2. sam4cm datasheet r ev. 11203b revision history doc. rev. 11203b changes 14-apr-14 removed preliminary status. in section ?features? , removed ?...or using internal voltage regulator.? from note (1) . in figure 2-1 ?sam4cm series 100-pin block diagram? , removed 100mhz from cortex-m4 blocks. table 5-2 ?low-power mode configuration summary? : updated notes (4) and (5) . in figure 8-6 ?execution view? , in core 1 block, changed the incoming sram bus to icode/dcode bus . section 27. ?static memo ry controller (smc)? section 27.1 ?description? : removed reference to configurable 16-bit data bus in 3rd paragraph. table 27-1 ?i/o line description? : table contents modified. removed section ?multiplexed signals?. section 27.2 ?embedded characteristics? : removed reference to 16-bit datas bus in 3rd bullet. section 27.15.4 ?smc mode register? : removed bit 12 ?dbw?. section 41. ?energy metering analog front end (emafe)? figure 41-1 ?functional block diagram for three-phase emafe? , figure 41-2 ?functional block diagram for two-phase emafe?, figure 41-3 ?typical three-phase application block diagram? and figure 41-4 ?typical single-phase application block diagram? : modified all instances of vref to vref_afe. continued on next page
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 1168 14-apr-14 section 47. ?sam4cm electrical characteristics? table 47-1 ?absolute maximum ratings*? : removed junction temperature. in table 47-16 ?lcd voltage regulator characteristics? , changed min and max values for v vddlcd ?output voltage accuracy? parameter. added new characteristic d vout /d vddin ?vddlcd variation with vddin? with typ and max values. in table 47-17 ?vddlcd voltage selection at vddin = 3.6v? , all vddlcd values updated. in table 47-18 ?lcd buffers characteristics? , changed min, typ and max values for z out ?buffer output impedance?. changed convergence value and max value for t r / t f ?rising or falling time?. table 47-21 ?vddio supply monitor? : modified min and max values for parameter acc table 47-26 ?4/8/12 mhz rc oscillators characteristics? : modified conditions for acc4, acc8 and acc12. modified max values for acc8 and acc12. in table 47-31 ?plla characteristics? , modified t on ?startup time?. added new t lock ?lock time?. table 47-41 ?programmable volt age reference characteristics? : modified acc ?reference voltage accuracy? min and max values and added conditions. modified max value of t c ?temperature coefficient?. table 47-42 ?programmable voltage reference selection values? : all advref values modified. in table 47-45 ?current or voltage measurem ent channel electrical characteristics? , added condition ?gain = 1, v ind = 0.500 v pp ? with typ value for parameter sinad peak table 47-46 ?emafe precision voltage referenc e and die temperature sensor characteristics? : changed min/typ/max values of parameter v ref_afe0. table 47-47 ?emafe vdda ldo regulator? : updated min, typ and max values and modified units for parameters static load regulation and static line regulation. changed typ value for parameter power supply rejection ration for condition f = 1 mhz. figure 45-18 ?measurement setup for configuration c and d? : added note below figure. table 47-52 ?typical current consumption val ues for backup mode configurations c and d? : modified ?conditions? column to vddio. removed section 46.5.17.2 ?10-bit adc with averager?. table 47-57 ?test setup 3 current consumption? : modified values for 128-bit flash access, cache enabled columns. table 46-61 ?wake-up time versus low-power mode? : all consumption values modified except aes. removed section 46.7.6 ?low-power mode wake-up time?. section 51. ?errata? added erratum on flash memory: ?flash: incorrect flash read may occur depending on vddio voltage and flash wait state? added erratum on efc: ?erase sector (es) command cannot be performed if a subsector is locked (only in flash sector 0)? table 53-2. sam4cm datasheet rev. 1 1203b revision history (continued) doc. rev. 11203b changes table 53-3. sam4cm datasheet rev. 11203a 15-oct-13 revision history doc. rev. 11203a changes 15-oct-13 first issue
i sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 table of contents description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1. configuration summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2. block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3. signal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 4. package and pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.1 sam4cm series 100-lead lqfp package outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.2 100-lead lqfp pinout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5. power supply and power control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.1 power supplies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.2 clock system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.3 system state at power-up. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5.4 active mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5.5 low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 5.6 wake-up sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 5.7 fast start-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 6. input/output lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6.1 general-purpose i/o lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6.2 system i/o lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 6.3 tst pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 6.4 nrst pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 6.5 tmpx pins: anti-tamper pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 6.6 rtcout0 pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 6.7 shutdown (shdn) pin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 6.8 force wake-up (fwup) pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 6.9 erase pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 7. product mapping and peripheral access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 8. memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 8.1 embedded memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 8.2 external memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 9. real-time event management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 9.1 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 9.2 real-time event mapping list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 10. system controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 10.1 system controller and peripheral mapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 10.2 power supply monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 10.3 reset controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 10.4 supply controller (supc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 11. peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 11.1 peripheral identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 ii 11.2 peripheral dma controller (pdc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 11.3 apb/ahb bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 11.4 peripheral signal multiplexing on i/o lines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 12. arm cortex-m4 processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 12.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 12.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 12.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 12.4 cortex-m4 models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 12.5 power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 12.6 cortex-m4 instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 12.7 cortex-m4 core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 12.8 nested vectored interrupt controller (n vic). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 12.9 system control block (scb) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 12.10 system timer (systick) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 12.11 memory protection unit (mpu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 12.12 floating point unit (fpu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 12.13 glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 13. debug and test features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 13.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 13.2 associated documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 13.3 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 13.4 cross triggering debut events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 13.5 application examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 13.6 debug and test pin description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 13.7 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 14. boot program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 14.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 14.2 hardware and software constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 14.3 flow diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 14.4 device initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 14.5 sam-ba monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 15. reset controller (rstc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 15.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 15.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 15.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 15.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 15.5 reset controller (rstc) user interfac e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330 16. real-time timer (rtt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 16.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 16.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 16.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 16.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 16.5 real-time timer (rtt) user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 17. real-time clock (rtc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 17.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 17.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
iii sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 17.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 17.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 17.5 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 17.6 real-time clock (rtc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352 18. watchdog timer (wdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 18.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 18.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 18.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 18.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 18.5 watchdog timer (wdt) user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 19. reinforced safety watchdog timer (rswdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382 19.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382 19.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382 19.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 19.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 19.5 reinforced safety watchdog timer (rswdt) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386 20. supply controller (supc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391 20.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391 20.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391 20.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 20.4 supply controller functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 20.5 register write protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 20.6 supply controller (supc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405 21. general purpose backup registers (gpbr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 21.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 21.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 21.3 general purpose backup registers (gpbr) user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 22. enhanced embedded flash controller (eefc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 22.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 22.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 22.3 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 22.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 22.5 enhanced embedded flash controller (eefc) user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . 436 23. fast flash programming interface (ffpi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 23.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 23.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 23.3 parallel fast flash programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444 24. cortex m cache controller (cmcc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 24.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 24.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 24.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 24.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 24.5 cortex m cache controller (cmcc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 25. interprocessor communication (ipc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 25.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 iv 25.2 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 25.3 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 25.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 25.5 inter-processor communication (ipc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468 26. bus matrix (matrix) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 26.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 26.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 26.3 special bus granting mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480 26.4 no default master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480 26.5 last access master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480 26.6 fixed default master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480 26.7 arbitration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 26.8 register write protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 26.9 ahb bus matrix (matrix) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 27. static memory controller (smc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 27.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 27.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 27.3 i/o lines description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495 27.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495 27.5 multiplexed signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495 27.6 external memory mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496 27.7 connection to external devi ces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 27.8 application example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500 27.9 standard read and write protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502 27.10 scrambling/unscrambling function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510 27.11 automatic wait states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510 27.12 data float wait states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515 27.13 external wait . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 27.14 slow clock mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 27.15 asynchronous page mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 27.16 static memory controller (s mc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530 28. peripheral dma controller (pdc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 28.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 28.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 28.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542 28.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 28.5 peripheral dma controller (pdc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545 29. clock generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556 29.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556 29.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556 29.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557 29.4 slow clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558 29.5 main clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559 29.6 divider and pll block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563 30. power management controller (pmc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565 30.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565 30.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
v sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 30.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566 30.4 master clock controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 30.5 processor clock controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 30.6 systick clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 30.7 peripheral clock controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 30.8 free-running processor clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568 30.9 programmable clock output controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568 30.10 main processor fast startup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568 30.11 main processor startup from embedded flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 70 30.12 coprocessor sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570 30.13 main clock failure detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570 30.14 slow crystal clock frequency monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571 30.15 programming sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571 30.16 clock switching details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574 30.17 register write protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 30.18 power management controller (pmc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578 31. chip identifier (chipid) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609 31.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609 31.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609 31.3 chip identifier (chipid) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610 32. parallel input/output (pio3) controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615 32.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615 32.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616 32.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617 32.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617 32.5 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619 32.6 parallel input/output controller (pio) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629 33. serial peripheral interface (spi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680 33.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680 33.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681 33.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682 33.4 application block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682 33.5 signal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683 33.6 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683 33.7 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684 33.8 serial peripheral interface (spi) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698 34. two-wire interface (twi2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714 34.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714 34.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714 34.3 list of abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715 34.4 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715 34.5 application block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716 34.6 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716 34.7 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717 34.8 two-wire interface (twi2) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743 35. universal asynchronous recei ver transmitter (uart) . . . . . . . . . . . . . . . . . . . . . . . . . 760 35.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 760
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 vi 35.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 760 35.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 760 35.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761 35.5 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761 35.6 universal asynchronous receiver transmitter (uart) user interface . . . . . . . . . . . . . . . . . . . . . 770 36. universal synchronous asynchronous receiver transmitter (usart) . . . . . . . . . 782 36.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782 36.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782 36.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783 36.4 i/o lines description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783 36.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784 36.6 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 786 36.7 universal synchronous asynchronous receiver transm itter (usart) user interface . . . . . . . . . 816 37. timer counter (tc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 2 37.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 852 37.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853 37.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854 37.4 pin name list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855 37.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855 37.6 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856 37.7 timer counter (tc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875 38. pulse width modulation controller (pwm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905 38.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905 38.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905 38.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906 38.4 i/o lines description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906 38.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906 38.6 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908 38.7 pulse width modulation controller (pwm) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915 39. segment liquid crystal display controller (slcdc) . . . . . . . . . . . . . . . . . . . . . . . . . . . 930 39.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 930 39.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 931 39.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 932 39.4 i/o lines description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933 39.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933 39.6 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936 39.7 waveform specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 950 39.8 segment lcd controller (slcdc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 951 40. analog-to-digital converter (adc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968 40.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968 40.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969 40.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 970 40.4 signal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 970 40.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 971 40.6 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972 40.7 analog-to-digital converter (adc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984
vii sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 41. energy metering analog front end (emafe) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008 41.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008 41.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008 41.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009 41.4 signal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1011 41.5 application block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1012 41.6 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1013 42. advanced encryption standard (aes) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1015 42.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1015 42.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1015 42.3 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016 42.4 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016 42.5 advanced encryption standard (aes) user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028 43. integrity check monitor (icm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047 43.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047 43.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048 43.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048 43.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049 43.5 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049 43.6 programming the icm for mult iple regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1060 43.7 integrity check monitor (icm) user inte rface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1061 44. classical public key cryptography controller (cpkcc) . . . . . . . . . . . . . . . . . . . . . . . 1075 44.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075 44.2 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076 44.3 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076 45. true random number generator (trng) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077 45.1 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077 45.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077 45.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077 45.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078 45.5 functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078 45.6 true random number generator (trng) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1079 46. electrical characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1086 46.1 absolute maximum ratings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1086 46.2 recommended operating conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087 46.3 electrical parameters usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1088 46.4 i/o characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089 46.5 embedded analog peripherals characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 02 46.6 embedded flash characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1122 46.7 power supply current consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1124 47. mechanical characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1145 47.1 100-lead lqfp package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1145 47.2 soldering profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1146 47.3 packaging resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1146 48. marking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1147
sam4cm series [datasheet] atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14 viii 49. ordering information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1148 50. sam4cm16/8 errata revision a (mrl a) parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1149 50.1 device identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1149 50.2 flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1150 50.3 supply controller (supc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1150 50.4 parallel input output (pio) controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151 50.5 watchdog (wdt) / reinforced safety watchdog (rswdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151 50.6 enhanced embedded flash controller (eefc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1152 50.7 wait for interrupt (wfi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1152 50.8 power supply and power control / clock system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1152 50.9 power management controller (pmc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1152 51. sam4cm16/8 errata revision b (mrl b) parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153 51.1 device identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153 51.2 supply controller (supc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153 51.3 parallel input output (pio) controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1154 51.4 watchdog (wdt) / reinforced safety watchdog (rswdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1154 51.5 enhanced embedded flash controller (eefc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1155 51.6 wait for interrupt (wfi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1155 51.7 power supply and power control / clock system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1155 51.8 power management controller (pmc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1155 52. sam4cm32 errata revision a (mrl a) parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1156 52.1 device identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1156 52.2 supply controller (supc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1156 52.3 parallel input output (pio) controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1157 52.4 reinforced safety watchdog (rswdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1157 52.5 enhanced embedded flash controller (eefc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1157 52.6 wait for interrupt (wfi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1158 52.7 power management controller (pmc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1158 53. revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1159 table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .i
x x x x x x arm connected logo atmel corporation 1600 technology drive, san jose, ca 95110 usa t: (+1)(408) 441.0311 f: (+1)(408) 436.4200 | www.atmel.com ? 2014 atmel corporation. / rev.: atmel-11203c-atarm-sam4cm32-sam4cm16-sam4cm8-datasheet_06-oct-14. atmel ? , atmel logo and combinations thereof, enabling unlimited possibilities ? , and others are registered trademarks or trademarks of atmel corporation in u.s. and other countries. arm ? , arm connected ? logo, and others are the registered trademarks or trademarks of arm ltd. other terms and product names may be trademarks of others. disclaimer: the information in this document is provided in connection with atmel products. no license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of atmel products. except as set forth in the atmel terms and condit ions of sales located on the atmel website, atmel assumes no liability whatsoever and disclaims any express, implied or statutory warranty relating to its p roducts including, but not limited to, the implied warranty of merchantability, fitness for a particular purpose, or non-infringement. in no event shall atmel be liable for any direct, indirect, consequential, pu nitive, special or incidental damages (including, without limi tation, damages for loss and profits, business interruption, or loss of information ) arising out of the use or inability to use this document, even if atmel has been advised of the possibility of such damages. atmel makes no r epresentations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specificatio ns and products descriptions at any time without notice. atmel d oes not make any commitment to update the information contained herein. unless specifically provided otherwise, atme l products are not suitable for, and shall not be used in, automo tive applications. atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. safety-critical, military, and automotive applications disclaim er: atmel products are not designed for and will not be used in connection with any applications where the failure of such products would reasonably be expected to re sult in significant personal inju ry or death (?safety-critical a pplications?) without an atmel officer's specific written consent. safety-critical applications incl ude, without limitation, life support devices and systems, equipment or systems for t he operation of nuclear facilities and weapons systems. atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by atmel as military- grade. atmel products are not designed nor intended for use in automot ive applications unless spec ifically designated by atmel as automotive-grade.


▲Up To Search▲   

 
Price & Availability of SAM4CM-14

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X